开发者

why callback parameter is added to query string using jQuery AJAX request

I write in MVC and send jQuery AJAX request.

I don't understand why the 'callback' parameter is added to query string when I send AJAX request using JQUERY as below

http://localhost:39224/Test/TAction/2?callback=jQuery151031896859929189747_1301556762907

This causes error when response is returned I have never encountered such a problem. What it can be?

here the request code Thank you

$.ajax({
         type: 'POST',
         dataType: 'json',
         url: 'Test/TAction/' + id,
         async: false,                   
         success: function (data, textStatus, XMLHttpRequest) {
              var branches =开发者_JAVA百科 $.parseJSON(data);
         },
         error: function (a, b, c) {
              var d = 1;
         }
});


As per the docs for the jsonp setting of .ajax():

Override the callback function name in a jsonp request. This value will be used instead of 'callback' in the 'callback=?' part of the query string in the url. So {jsonp:'onJSONPLoad'} would result in 'onJSONPLoad=?' passed to the server. As of jQuery 1.5, setting the jsonp option to false prevents jQuery from adding the "?callback" string to the URL or attempting to use "=?" for transformation. In this case, you should also explicitly set the jsonpCallback setting. For example, { jsonp: false, jsonpCallback: "callbackName" }

I.e., it seems to me that you need to explicitly set jsonp to false if you're using jQuery 1.5+, although I haven't tried it myself.


In jQuery-1.5 "?callback" is added automatically so you need to configure jSONP

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜