I have written a web service. I am calling this web service using JavaScript. I am calling this from different domain. For that I have added `[System.Web.Script.Services.ScriptService]` property in the web service. From JavaScript I am calling the service using **XMLHttpRequest**. I tested it using Firefox and everything was fine when. But it was not working in IE.
After some searching I found that this is an issue related to **Cross domain calling**. I have gone through some of the questions posted here. And then I did the following changes in my code -
1. From javaScript I am now calling the service using **XDomainRequest**.
2. I have added following lines befor the return statements in the web-service - `HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Credentials", "true");
return result;`
It is still working fine in firefox. but in IE8 (as per my knowledge, XDomainRequest will not work in lower versions of IE) it is showing error (**XDomainRequest.onerror**).
Am I missing something?
以上就是Calling cross domain asmx web service using JavaScript的详细内容,更多请关注web前端其它相关文章!