最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - XMLHttpRequest for http: required Cross Origin Resource Sharing (CORS) and preflight only happen in IE - Stack Over

programmeradmin0浏览0评论

I am a front-end developer. I'm coding only with client side so I don't know for sure about the error exist. I've searching about CORS, but still no idea what did my problem course.

I'm trying to post data to REST.

$.ajax({
     url        : urlPost,
     type       : "POST",
     data       : JSON.stringify(obj),
     dataType   : "json",
     contentType: "application/json",

     success: function(res){
         console.log(JSON.stringify(res));
     },

     error: function(res){
         console.log("Bad thing happend! " + res.statusText);
     }
});

Headers of web service show in firebug of firedfox :

It is working for all the browser that I used, except in IE 10, I got two errors:

  1. SEC7118: XMLHttpRequest for http://mysite/project/wl.svc/AddWL/ required Cross Origin Resource Sharing (CORS).

  2. SEC7119: XMLHttpRequest for http://mysite/project/wl.svc/AddWL/ required CORS preflight.

I am a front-end developer. I'm coding only with client side so I don't know for sure about the error exist. I've searching about CORS, but still no idea what did my problem course.

I'm trying to post data to REST.

$.ajax({
     url        : urlPost,
     type       : "POST",
     data       : JSON.stringify(obj),
     dataType   : "json",
     contentType: "application/json",

     success: function(res){
         console.log(JSON.stringify(res));
     },

     error: function(res){
         console.log("Bad thing happend! " + res.statusText);
     }
});

Headers of web service show in firebug of firedfox :

It is working for all the browser that I used, except in IE 10, I got two errors:

  1. SEC7118: XMLHttpRequest for http://mysite/project/wl.svc/AddWL/ required Cross Origin Resource Sharing (CORS).

  2. SEC7119: XMLHttpRequest for http://mysite/project/wl.svc/AddWL/ required CORS preflight.

Share Improve this question edited Mar 26, 2014 at 7:42 user432219 asked Nov 23, 2013 at 7:54 NothingNothing 2,64212 gold badges67 silver badges117 bronze badges 11
  • Is the urlPost to same domain where from document was loaded? Are you using SSL? Is the document inside IFRAME? In any case, CORS will need special headers from server to work. It can not be configured only from client side. – Teemu Ikonen Commented Nov 23, 2013 at 8:43
  • But I wonder, it works well with Chrome, Firefox excepts IE. – Nothing Commented Nov 23, 2013 at 9:12
  • urlPost is in different domain with document loading domain. I updated my question with the Headers. – Nothing Commented Nov 23, 2013 at 9:16
  • Check this: blogs.msdn./b/ie/archive/2012/02/09/… – Teemu Ikonen Commented Nov 23, 2013 at 9:20
  • 1 jQuery does not support CORS requests in IE<10. If you want to perform CORS requests in IE<10 with jquery, you must either extend jquery's ajax method with a new transport that supports IE XDomainRequest, or not use jQuery to perform your ajax. – Kevin B Commented Mar 7, 2014 at 23:30
 |  Show 6 more ments

1 Answer 1

Reset to default 1

I think you have a CORS, so I remend you to take a look at cors-anywhere

I have used it and it works fine all what you need to append your request url to https://cors-anywhere.herokuapp./ which it is a Proxy server to request the chosen URL

var cors_api_url = 'https://cors-anywhere.herokuapp./' + urlPost;

$.ajax({
     url        : cors_api_url,
     type       : "POST",
     data       : JSON.stringify(obj),
     dataType   : "json",
     contentType: "application/json",

     success: function(res){
         console.log(JSON.stringify(res));
     },

     error: function(res){
         console.log("Bad thing happend! " + res.statusText);
     }
});

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论