Reputation: 211
I guess this question is not asked in this forum before, tried searching alot but none matched or worked for me. Below is the JSFiddle link of code:
Everything is working well in IE8 and IE9 but not in any other browsers. I tried looking for the problem in Chrome from which I got
XMLHttpRequest cannot load http://v3.actisku.com/GetUserPostData?pid=Test-37&surv=1170. Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers
I tried searching for necessary solution i.e CORS but couldn't figure out the solution. I am side by side looking for the same.
EDIT:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<html><head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function () {
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
var contents = $.ajax({
url: 'http://v3.actisku.com/GetUserPostData?pid=Test-37',
cache: false,
crossDomain: true,
dataType: 'html',
data: { surv: '1170'},
async: false
}).responseText;
var test = contents;
alert(test);
test = test.replace(/\t/g, ';');
alert(test);
test = test.replace(/\n/g, 'break');
alert(test);
$('#contentArea').attr('value', test);
});
</script>
</head>
<body>
<textarea id="contentArea" rows="10" cols="50"></textarea>
</body>
</html>
Can we manually add headers so that the server feels like it is getting request from IE itself.
Regards, icr
Upvotes: 0
Views: 366
Reputation: 19327
ok as says there... "Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers" all AJAX/XHR requests are blocked by the server. Please try to contact the server administrator about the server configuration
the IE uses a different way to send ajax request(so they were not blocked) because they are using ActiveXObject("Msxml2.XMLHTTP")
or ActiveXObject("Microsoft.XMLHTTP")
which the server maybe reads them differently as they are passed to the headers.
Upvotes: 2
Reputation: 78941
There is nothing in your code, to create Browser incompatibility. In fact they ware working fine in Firefox, and chrome. However, This seems unnecessary.
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
As mentioned by Mahan, this looks to be like Server Configuration problem.
Upvotes: 0