0

I am trying to use JQuery to send a JavaScript Array object over Ajax. Everything i have read points to using a JSON array, can it not be done with a standard Array?

Example:

   var data = new Array;
   data['type']  = 'author_list';
   data['limit'] = 10;

   $.ajax(
   {
      url      : '/transporter.php/',
      dataType : 'json',
      data     :  data,
      type     :  'GET',
      success  : function(json) 
      {
         console.log(json);
      }
   });

This method is what i use when working with DOJO. I am hoping its the same with JQuery..

Thanks,

1 Answer 1

5

You want to use an object and not an array:

  var data = {};
   data['type']  = 'author_list';
   data['limit'] = 10;

   $.ajax(
   {
      url      : '/transporter.php/',
      dataType : 'json',
      data     :  data,
      type     :  'GET',
      success  : function(json) 
      {
         console.log(json);
      }
   });

Also, JSON is what will be returned by the page you are requesting, not what you are sending to that page. JSON is a string representation of an object, you are passing an actual object to the ajax method.

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

Comments

Your Answer

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.