问题描述
我收到一个错误(XMLHtt prequest无法加载https://开头www.cloudflare.com/api_json.html?tkn=&email=&z=&a=rec_load_all& ;回调=%3F产地的http:// domainmanager.tech-bytes.org没有被允许访问控制允许来源)
(空格插入网址,由于堆栈溢出链接限制)当试图通过jQuery发送JSONP请求的CloudFlare。该指出,可以的通过附加要求一个JSONP回调一个&安培;回调= myCallBack函数
参数的。我不知道我是否应该更换的东西,我试着用它代替myCallBack函数?因为这是其他一些资源说什么,或者如果我不得不做一些其他修改我的code 。
I recieve an error (XMLHttpRequest cannot load https:// www.cloudflare.com/api_json.html?tkn=&email=&z=&a=rec_load_all&callback=%3F. Origin http:// domainmanager.tech-bytes.org is not allowed by Access-Control-Allow-Origin.)
(spaces inserted in URLs due to Stack Overflow link limit) when trying to send a JSONP request via jQuery to CloudFlare. The CloudFlare API states that you can ask for a JSONP callback by appending a &callback=mycallback
parameter. I am not sure if I am supposed to replace mycallback with something, I tried replacing it with ? as that is what some other resources said, or if I have to do some other modifications to my code.
推荐答案
尝试以这种方式跨域请求。
Try in this way for cross domain request.
$.ajax({ url: "yourUrl",
data:{paramName1: JSON.stringify(paramValue1),paramName2: JSON.stringify(paramValue2)},
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
success: function(data) {
alert(data.d);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
这篇关于使用jQuery JSONP与CloudFlare的API时同源策略错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!