1

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
1
  • BTW, you should reconsider using a asynchronous request instead of synchronous. Synchronous requests lock up the browser giving the user a bad experience. Commented Feb 20, 2012 at 10:08

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

data: { 'userarray': userarray }

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.