JQuery.Ajax makes an invalid request with array data

I have the following array:

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

I want to send this data as a request using jQuery.ajaxwhat I am doing:

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

But as a result, I have the following ugly line: ?id[]=1&id[]=2&id[]=4(actually it is much uglier :) id%5B%5D=1&id%5B%5D=2&id%5B%5D=4.

What to do to get a normal line like: id=1&id=2&id=4?? Thanks

+3
source share
1 answer

I assume this is with jQuery 1.4. You need to use the parameter traditional: trueto$.ajax()

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

jQuery 1.4, $.param() , PHP Ruby on Rails. , jQuery.ajaxSettings.traditional = true;.

+7

Source: https://habr.com/ru/post/1742376/


All Articles