javascript - 这个ajax有 jsonpCallBack写法??
PHP中文网
PHP中文网 2017-04-10 15:03:29
[JavaScript讨论组]
$.ajax({
                    type : "get",
                    //async:false,
                    url : "http://127.0.0.1:8080/html/test.txt",
                    dataType : "jsonp",
                    jsonpCallback : "success_jsonpCallback",
                    success : function(json) {

                    },
                    error : function() {
                        alert(strs);
                    }
                });

上面那个jsonpCallback属性好像$.ajax下没有的吧?是可以自定义的吗?那怎么认啊

PHP中文网
PHP中文网

认证0级讲师

全部回复(4)
巴扎黑

怎么没有 http://api.jquery.com/jQuery.ajax/

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.

ringa_lee

跨域ajax

伊谢尔伦

jsonpCallback是实现跨域请求的时候定义回调函数用的

阿神

不涉及到跨域请求,你上面的“jsonpCallback”可以删掉。
只有当你的请求连接出现类似这"callback=?"这东西的时候,如:
http://127.0.0.1/text.jsonp?callback=?
这时候,jsonpCallback才会生效。

但是,一般我们会这么使用:
$.getJSON("http://127.0.0.1/text.jsonp?callback=?", function(data){
console.log("执行完成...");
});

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号