469,272 Members | 1,432 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,272 developers. It's quick & easy.

SOP problem in AJAX especially with IE

RamananKalirajan
607 512MB
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
5 2258
acoder
16,027 Expert Mod 8TB
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
607 512MB
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
16,027 Expert Mod 8TB
No, I meant directly without using Ajax.
Aug 11 '08 #4
RamananKalirajan
607 512MB
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
16,027 Expert Mod 8TB
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.

Similar topics

9 posts views Thread by Matt Kruse | last post: by
2 posts views Thread by Larry | last post: by
4 posts views Thread by VK | last post: by
1 post views Thread by codefragment | last post: by
1 post views Thread by tysu | last post: by
17 posts views Thread by Arjen | last post: by
8 posts views Thread by BillE | last post: by
8 posts views Thread by Bill Gower | last post: by
2 posts views Thread by KBS Tours Development | last post: by
4 posts views Thread by ton | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.