dataType的JSONP和JSON的区别 [英] Difference between dataType jsonp and JSON

查看:1167
本文介绍了dataType的JSONP和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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆