Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to retrieve array data at jquery ajax
    text
    copied!<p>I want to call a codeigniter controller function from ajax jquery function, and on success i am getting the result in array form. I need to output the array values into different text fields. how can i retrieve the array values with jquery ajax. My code,</p> <pre><code>&lt;?php echo form_open(base_url().'index.php/tapal'); ?&gt; &lt;table class="register-table"&gt; &lt;tr&gt; &lt;td&gt;Tapal No.&lt;/td&gt; &lt;td&gt;&lt;input type="text" class="tapal_no" name="Tyear" id="Tyear" placeholder="&lt;?php echo date('Y');?&gt;" /&gt; &lt;input type="text" class="tapal_no" name="Tno" id="Tno" /&gt; &lt;input type="text" class="tapal_no" name="Tdist" id="Tdist" placeholder="7" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;label for="T_sender"&gt;Sender Code&lt;span class="required_field"&gt;*&lt;/span&gt;&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;select id="T_sender" name="T_sender"&gt; &lt;option value=""&gt;&lt;/option&gt; &lt;?php if(isset($Tsender)) : foreach($Tsender as $send) : ?&gt; &lt;?php echo "&lt;option value=".$send-&gt;add_id."&gt;".$send-&gt;add_name.",&amp;nbsp;".$send-&gt;add_line1."&lt;/option&gt;"; ?&gt; &lt;?php endforeach; ?&gt; &lt;?php else : ?&gt; &lt;option value=""&gt;&lt;/option&gt; &lt;?php endif; ?&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Sender Name&lt;/td&gt; &lt;td&gt;&lt;input type="text" class="text-input" name="send_name" id="send_name" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td rowspan="3"&gt;Address&lt;/td&gt; &lt;td rowspan="3"&gt;&lt;div&gt;&lt;input type="text" class="text-input" name="add_line1" id="add_line1" placeholder="Building Name/ No." /&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="text" class="text-input" name="add_line2" id="add_line2" placeholder="Street/ Lane" /&gt; &lt;/div&gt; &lt;div&gt;&lt;input type="text" class="text-input" name="add_line3" id="add_line3" placeholder="City/ Dist" /&gt; &lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;?php echo form_close(); ?&gt; </code></pre> <p>And the jquery function ,</p> <pre><code>&lt;script type="text/javascript"&gt; $(function(){ $("#T_sender").change(function(){ var sender_code = $(this).val(); var out = $("#send_name"); var ajax_data = { sender_code:sender_code, action:'findaddress' }; $.ajax({ url: "&lt;?php echo site_url('tapal/tapalajaxqry'); ?&gt;", type: 'POST', data: ajax_data, success: function(msg) { $("#send_name").val(msg); } }); }); }) &lt;/script&gt; </code></pre> <p>And the controller function,</p> <pre><code> function tapalajaxqry() { if(strncmp($this-&gt;input-&gt;post('action'),'findaddress',11) == 0){ if($query = $this-&gt;tapal_model-&gt;get_Taddress($this-&gt;input-&gt;post('sender_code'))) return $query; } } </code></pre> <p>How can i get the array values,and output them (sender name,address line1,address line2,etc) into corresponding text fields?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload