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:
SEC7118: XMLHttpRequest for
http://mysite/project/wl.svc/AddWL/
required Cross Origin Resource Sharing (CORS).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:
SEC7118: XMLHttpRequest for
http://mysite/project/wl.svc/AddWL/
required Cross Origin Resource Sharing (CORS).SEC7119: XMLHttpRequest for
http://mysite/project/wl.svc/AddWL/
required CORS preflight.
- 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
1 Answer
Reset to default 1I 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);
}
});