Passing arrays from AJAX to HTML to PHP - Is this Possible? -


i have ajax call returning array php-html page.


here blocks of codes:

javascript:

"note: get_data.php returns html string, , want store in array."

var param_array = new array(); $.post('get_data.php', { id: id }, function(data)) {     param_array.push(data);     $('#hidden_input').val(param_array); } 

html:

<form action='my_function' method='post'>     <input type='hidden' id='hidden_input' name='array_from_ajax'>     <input type='submit' name='btn_submit'> </form> 

php - codeigniter:

my_function() {     $param_array = $this->input->post('array_from_ajax');     print_r($param_array); // work? $param_array contain value? } 

questions:

  1. is possible return array value , insert html page?
  2. is javascript array same php array?
  3. in end, $param_array in php contain value passed ajax call?

javascript , php can communicate on http , via strings (unless soap guess, if that's possible). there no compatibility in data structures between them, javascript array <> php array. similarly, can't set input value javascript array.

the best way handle json-encode array before setting value of input. php can decode json data structures can use.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -