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?

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

Sign up to request clarification or add additional context in comments.

1 Comment

data: { 'userarray': userarray }

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.