jquery jsonp异步请求,success和jsonpCallback的区别

 我来答
树影雨下
2017-11-07 · TA获得超过225个赞
知道小有建树答主
回答量:198
采纳率:76%
帮助的人:151万
展开全部
$.ajax({
url:
type: ‘GET’,
dataType: ‘jsonp’,
success:getGoodsList
});
$.ajax({
url:
type: ‘GET’,
dataType: ‘jsonp’,
jsonpCallback:getGoodsList
});
success
Type: Function( Anything data, String textStatus, jqXHR jqXHR )
A function to be called if the request succeeds. The function gets passed three arguments: The data returned from the server, formatted according to the dataType parameter or the dataFilter callback function, if specified; a string describing the status; and the jqXHR (in jQuery 1.4.x, XMLHttpRequest) object. As of jQuery 1.5, the success setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event.
jsonpCallback
Type: String or Function()
Specify the callback function name for a JSONP request. This value will be used instead of the random name automatically generated by jQuery. It is preferable to let jQuery generate a unique name as it’ll make it easier to manage the requests and provide callbacks and error handling. You may want to specify the callback when you want to enable better browser caching of GET requests. As of jQuery 1.5, you can also use a function for this setting, in which case the value of jsonpCallback is set to the return value of that function.
循环调用ajax的时候,由于循环的结果参数都在变化,如果回调函数需要获取调用ajax时作用域空间的值,则使用success,
如果使用jsonpCallback,获取值可能会混乱。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式