这个ajax有 jsonpCallBack写法??

$.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下没有的吧?是可以自定义的吗?那怎么认啊

阅读 19k
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.

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("执行完成...");
});

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题