使用jQuery JSONP与CloudFlare的API时同源策略错误 [英] Same Origin Policy Error when using jQuery JSONP with CloudFlare API

查看:133
本文介绍了使用jQuery JSONP与CloudFlare的API时同源策略错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个错误(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。该 CloudFlare的API 指出,可以的通过附加要求一个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时同源策略错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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