开发者

Ajax - JQuery, Array to query string

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 whe开发者_如何学编程n working with DOJO. I am hoping its the same with JQuery..

Thanks,


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜