Jump to content

Passing A Php Array To Javascript?


Solarpitch

Recommended Posts

Hey Guys,

 

Just trying to pass a php array to a Javascript function but I keep getting undefined. I'm sure my syntax is slightly incorrect.

 

PHP

 

...
$arr = array();
$arr[0] = $this->load->view('video',);
$arr[1] = "A String";

return json_encode($arr); // this returns to the below Javascript $.POST responce.

 

Javascript

 

...
$.post('http://mysite.com//api/ajaxApiCall', 'val=' + val, function (response) {

alert(response[0]);
alert(response[1]);

});

Link to comment
https://forums.phpfreaks.com/topic/270276-passing-a-php-array-to-javascript/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.