mimic mimic - 1 year ago 68
Ajax Question

jQuery.Ajax makes the wrong request with array data

I have the following array:

var idParam = ["1","2","3"];

I want to send this data as request using
, what I'm doing:

type: "GET",
url: "Services/GetInfo.ashx",
data: { "id": idParam },
contentType: "application/text",
dataType: "json",
success: function(result)
error: function(XMLHttpRequest, textStatus, errorThrown)

But as result I have the following ugly string:
(actually it's much uglier:

What to do to get the normal string like:

Answer Source

I'm assuming this is with jQuery 1.4 - You need to use the traditional: true parameter for $.ajax()

Or you can set it globally: (from $.param() docs)

As of jQuery 1.4, the $.param() method serializes deep objects recursively to accommodate modern scripting languages and frameworks such as PHP and Ruby on Rails. You can disable this functionality globally by setting jQuery.ajaxSettings.traditional = true;.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download