dataType的JSONP和JSON的区别 [英] Difference between dataType jsonp and JSON
问题描述
我下载jQuery UI的自动加载,寻求远程jsonp.html。这是阿贾克斯的功能,但我打开控制台..我看不到任何请求在我的控制台...
I download Jquery UI autoload, looking to remote-jsonp.html. This is ajax function but i open console.. I can't see any request in my console...
什么是dataType的区别;JSONP和数据类型;JSON
What is difference between dataType;"jsonp" and dataType;"JSON"
$( "#city" ).autocomplete({
source: function( request, response ) {
$.ajax({
url: "http://ws.geonames.org/searchJSON",
dataType: "jsonp",
data: {
featureClass: "P",
style: "full",
maxRows: 12,
name_startsWith: request.term
},
success: function( data ) {
response( $.map( data.geonames, function( item ) {
return {
label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
value: item.name
}
}));
}
});
},
参考 <一个href="http://jqueryui.com/demos/autocomplete/remote-jsonp.html">http://jqueryui.com/demos/autocomplete/remote-jsonp.html
推荐答案
数据类型:JSONP
跨域请求,这意味着要求不同的域和数据类型:JSON
对于同一领域同一产地的请求
dataType: jsonp
for cross-domain request, that means request to different domain and dataType: json
for same domain-same origin request.
在使用JSONP的JSON块负荷。增加一个额外的?回调=?到 您的网址的结尾指定回调。通过添加禁用缓存 查询字符串参数,_ = [时间戳],除非到高速缓存中的网址 选项设置为true。
Loads in a JSON block using JSONP. Adds an extra "?callback=?" to the end of your URL to specify the callback. Disables caching by appending a query string parameter, "_=[TIMESTAMP]", to the URL unless the cache option is set to true.
了解更多关于 同源策略
Read about same origin policy
了解更多关于 jQuery的AJAX
Read more about jQuery AJAX
这篇关于dataType的JSONP和JSON的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!