开发者

JQuery .post function dataType parameter seems not to do anything

开发者 https://www.devze.com 2023-02-14 16:51 出处:网络
Using JQuery version 1.4.4, I am unable to get a proper JSON output when I call .ajax or .post like the following:

Using JQuery version 1.4.4, I am unable to get a proper JSON output when I call .ajax or .post like the following:

$.ajax({type: "POST", url: callbackUri, data: { cow: ["oh", "hello", "there"]}, success: returnFunction, dataType: "json"});

or the following:

$.post(callbackUri, { cow: ["oh", "hello", "there"]}, returnFunction, "json");.

The body of the HTTP request looks like this in both cases:

cow%5B%5D=oh&cow%5B%5D=hello&cow%5B%5D=there

It's probably a very simple configuration issue. Any help is appreciated!开发者_如何学C


Based on your comment "The body of the HTTP request ... " you may be misunderstanding what the JSON option does. It specifies the type of data the request is expecting back from the server -- it has NOTHING to do with the format the data is sent to the server.

The body of the HTTP request is going to be the same in all cases, unless you create a json string and send it as a value.


There is nothing wrong with the data being sent to the server (HTTP request body).

The dataType parameter is what type the return value from the server should be. 'json' means that jQuery will auto-parse the response as JSON.

Check the response from your server, it may not be valid JSON.

0

精彩评论

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