This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Cross Site Script error while making AJAX call using Xmlhttprequest Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Cross Site Script error while making AJAX call using Xmlhttprequest " Watch "Cross Site Script error while making AJAX call using Xmlhttprequest " New topic
Author

Cross Site Script error while making AJAX call using Xmlhttprequest

soni lal
Greenhorn

Joined: Jan 31, 2011
Posts: 29
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
The server is supposed to be setting those headers and not all browsers support it.

Eric
 
 
subject: Cross Site Script error while making AJAX call using Xmlhttprequest
 
Similar Threads
How can I dynamically load js library with document.write inside?
how to call mutiple Ajax in multiple row with diff values
Notify Users before session expires
302 Found Error when Trying to get the contents of url using jsp
Security error accessing url