By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

SOP problem in AJAX especially with IE

RamananKalirajan
100+
P: 607
Hi those who were working in Ajax, will surely experienced with this problem. SOP - Single Origin Policy problem. I am doing a small work in Prototype Ajax. I did a sample work. When I am passing the URL to the Ajax call within the same directory. It is showing an exception "Access Denied". The cause for this exception is SOP. This occur only with the IE. Had anyone overcome this problem. If so means pls tell me that would be very helpful for me.

The sample code I worked out

[HTML]<html>
<head>
<title>Prototype GET Example</title>
<script type="text/javascript"src="prototype.js"></script>
<script type="text/javascript">
function requestCustomerInfo() {
var sId = document.getElementById("txtCustomerId").value;
var oOptions = {
method: "get",
onSuccess: function (oXHR, oJson) {
displayCustomerInfo(oXHR.responseText);
},
onFailure: function (oXHR, oJson) {
displayCustomerInfo("An error occurred: " +
oXHR.statusText);
},
onException: function (oXHR, oJson) {
displayCustomerInfo("An Exception occurred: " +
oXHR.statusText);
}
};
var oRequest = new Ajax.Request("demo1.html", oOptions);
}
function displayCustomerInfo(sText) {
var divCustomerInfo = document.getElementById("divCustomerInfo");
divCustomerInfo.innerHTML = sText;
}
</script>
</head>
<body>
<p>Enter customer ID number to retrieve information:</p>
<p>Customer ID: <input type="text" id="txtCustomerId" value="" /></p>
<p><input type="button" value="Get Customer Info" onclick="requestCustomerInfo()" /></p>
<div id="divCustomerInfo"></div>
</body>
</html>[/HTML]

This piece of code is working fine with all the other browser except the IE. If u wantto test this file, pls download the prototype.js from the site http://prototypejs.org/download and have the demo1.html file within the same folder. Then only u will be able to view the change. I am not using any server kind of stuff. Any one having solution to the SOP problem pls help me out

Regards
Ramanan Kalirajan
Aug 8 '08 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
If it's from the same server/directory, it won't be a same origin policy error.

If you access the demo1.html file directly, are there any problems?
Aug 9 '08 #2

RamananKalirajan
100+
P: 607
If it's from the same server/directory, it won't be a same origin policy error.

If you access the demo1.html file directly, are there any problems?
Yes, Mr. Acoder. It's showing an Exception namely Access Denied. I read about the Access Denied in google, from there i got it was due to SOP. You just try this code.

Regards
Ramanan Kalirajan
Aug 11 '08 #3

acoder
Expert Mod 15k+
P: 16,027
No, I meant directly without using Ajax.
Aug 11 '08 #4

RamananKalirajan
100+
P: 607
No, I meant directly without using Ajax.
Thanks Mr. Acoder, the code is working when it is run with a help of server. The server is responsible for classifying the errors. So my code is working good for on404 and other error cases also. My problem solved I am movind ahead over that. Thank you very much.

Regards
Ramanan Kalirajan
Aug 12 '08 #5

acoder
Expert Mod 15k+
P: 16,027
Glad to hear that you've got it working (even if a little unexpected ;))
Aug 12 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.