SOP problem in AJAX especially with IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    SOP problem in AJAX especially with IE

    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>Prototyp e GET Example</title>
    <script type="text/javascript"src= "prototype.js"> </script>
    <script type="text/javascript">
    function requestCustomer Info() {
    var sId = document.getEle mentById("txtCu stomerId").valu e;
    var oOptions = {
    method: "get",
    onSuccess: function (oXHR, oJson) {
    displayCustomer Info(oXHR.respo nseText);
    },
    onFailure: function (oXHR, oJson) {
    displayCustomer Info("An error occurred: " +
    oXHR.statusText );
    },
    onException: function (oXHR, oJson) {
    displayCustomer Info("An Exception occurred: " +
    oXHR.statusText );
    }
    };
    var oRequest = new Ajax.Request("d emo1.html", oOptions);
    }
    function displayCustomer Info(sText) {
    var divCustomerInfo = document.getEle mentById("divCu stomerInfo");
    divCustomerInfo .innerHTML = sText;
    }
    </script>
    </head>
    <body>
    <p>Enter customer ID number to retrieve information:</p>
    <p>Customer ID: <input type="text" id="txtCustomer Id" value="" /></p>
    <p><input type="button" value="Get Customer Info" onclick="reques tCustomerInfo() " /></p>
    <div id="divCustomer Info"></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
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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?

    Comment

    • RamananKalirajan
      Contributor
      • Mar 2008
      • 608

      #3
      Originally posted by acoder
      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

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        No, I meant directly without using Ajax.

        Comment

        • RamananKalirajan
          Contributor
          • Mar 2008
          • 608

          #5
          Originally posted by acoder
          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

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Glad to hear that you've got it working (even if a little unexpected ;))

            Comment

            Working...