Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cross Site Script error while making AJAX call using Xmlhttprequest

 
soni lal
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am facing Cross Site Script error while making AJAX call using XMLHttpRequest(). I used following code to resolve the issue : http.setRequestHeader("Access-Control-Allow-Origin","*");

Please find the code :
if (window.XMLHttpRequest) { // code for IE7+, FF, Chrome, Opera, Safari
http=new XMLHttpRequest();
}
else { // code for IE6, IE5
http=new ActiveXObject("Microsoft.XMLHTTP");
}
http.open("GET", url, true);
http.setRequestHeader("Access-Control-Allow-Origin","*");
http.send();


Issue : After adding this statement " http.setRequestHeader("Access-Control-Allow-Origin","*");" the AJAX call only is not happening.
I am not getting any error also.

But, not getting why it is not working.


Please help me. If any other way is there to solve Cross Site Script error then also suggest me.

Thanks in advance !!
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The server is supposed to be setting those headers and not all browsers support it.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic