File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 JavaScript Promises Essentials this week in the JavaScript 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cross Site Script error while making AJAX call using Xmlhttprequest