$.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下没有的吧?是可以自定义的吗?那怎么认啊
巴扎黑2017-04-10 15:05:29
怎么没有 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.
阿神2017-04-10 15:05:29
不涉及到跨域请求,你上面的“jsonpCallback”可以删掉。
只有当你的请求连接出现类似这"callback=?"这东西的时候,如:
http://127.0.0.1/text.jsonp?callback=?
这时候,jsonpCallback才会生效。
但是,一般我们会这么使用:
$.getJSON("http://127.0.0.1/text.jsonp?callback=?", function(data){
console.log("执行完成...");
});