需要帮助来解决ajax问题吗?

I create safari extension and i inject js in this extension. In this JS code i send ajax call which create following error in console. "Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers" here is my code:

this function i copied from net to solve cross domain issue but its not working please help me to figure out this.

function createCORSRequest(method, url) {

    var xhr = new XMLHttpRequest();
    if ("withCredentials" in xhr) {
        // XHR has 'withCredentials' property only if it supports CORS
        xhr.open(method, url, true);
    } else if (typeof XDomainRequest != "undefined") { // if IE use XDR
      xhr = new XDomainRequest();
      xhr.open(method, url);
   } else {
       xhr = null;
   }
   return xhr;
}


var request = createCORSRequest("get", "https://www.karmora.com/list.xml");

if (request) {
   // Define a callback function
   request.onload = function () {
};
   // Send request
   request.send();
}

$.get('https://example.com', function (data) {
    alert("Ajax call successfull");
});
查看全部
weixin_33695450
weixin_33695450
2015/04/16 22:30
  • cross-domain
  • ajax
  • javascript
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信

1个回复