How to send a javascript array to PHP using Jquery Ajax.(Note: i will get a Jsondata as a response of the PHP).Also how to get the array variable in php.
In Javascript:
var userarray=values.toString().split(',');
var jsonData = $.ajax({
url: "http://someURL/server/test.php",
data:userarray,
dataType:"json",
async: false
}).responseText;
var timedata = new google.visualization.DataTable(jsonData);
In PHP:
$userdata=$_GET['userarray'];
is it correct?
asked Feb 20, 2012 at 7:42
Ramprasad
8,09320 gold badges77 silver badges137 bronze badges
-
BTW, you should reconsider using a asynchronous request instead of synchronous. Synchronous requests lock up the browser giving the user a bad experience.RoToRa– RoToRa2012年02月20日 10:08:33 +00:00Commented Feb 20, 2012 at 10:08
1 Answer 1
Do this instead for your javascript:
var jsonData = $.ajax({
url: "http://someURL/server/test.php",
data: { 'userarray': userarray },
dataType:"json",
async: false
}).responseText;
Your PHP code should be as is
RoToRa
38.5k12 gold badges73 silver badges110 bronze badges
answered Feb 20, 2012 at 8:06
Ronald Borla
5864 silver badges19 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Ronald Borla
data: { 'userarray': userarray }
lang-js