1

I have a Html file locally with the following code

            <h1>This is session token </h1>
            <div id="noob"></div>

          <script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script> 
        <script>
        $(document).ready(function(){
        var sessiontoken;
         var randomUser = Math.round(Math.random() * 1000000);
             var supportCors = $.support.cors;
                       var sessiontoken ;

                       $.support.cors = true;

            $.ajax({
                           type: 'POST',
                           url: "https://abc.com/Gateway.Session/Session",
                           dataType: "json",
                           data: {
                               UserId: "TestUser" + randomUser,
                               CSK1: "abc",
                               CustId: "cde"
                           },
        success: function (data) {

                            $.support.cors = supportCors;
                            sessiontoken=data.Token;
                            alert(sessiontoken);
                            document.getElementById('noob').innerHTML = sessiontoken;

                           },
                           error: function (xhr, textStatus, error) {
                               $.support.cors = supportCors;
                                  alert("responseText: " + xhr.responseText);
                               alert("XHR statusText: " + xhr.statusText);
                               alert("textStatus: " + textStatus);
                               alert("error: " + error.message);
                           }


            });
          });

        </script>

This code when run locally(ex: c:/development/mypage.html) is generating session token after enabling the pop-up 'allow running javascript' " of IE7. i.e., ajax function in above javascript is returning 'success' when run locally and session token is generated. But when this code is deployed in server and opened in IE7 like (http:// localhost:8080/mypage.html), here ajax function of above script is returning 'error'.

As when we run the file locally we enabled the pop-up to allow running script. But when the file is deployed in server we won't get such pop-up as javascript runs itself when a html page is accessed from server. I am unable to figure out why control going to 'error' part o 'success' when we file from server

So how can i make this ajax function to return to 'success' part when accessed from server.

The file executes fine in chrome when accessed locally or from server.Now i need it to be working with IE7.

User 4.5.5
  • 1,311
  • 3
  • 12
  • 20
  • There are no reason for not to run this code in server, if you are getting error alert, that means JS is enabled in the localhost, check the console log for errors. – Sudip Pal Mar 11 '13 at 06:53
  • yes it is enabled from localhost i think.But i don't have a clue why the same file when accessed from local drive in IE7 gives desired output and when accessed from localhost in the same IE7 browser is giving error.I think the instance of IE7 after enabling 'run script' pop-up when running file from local disk and instance of IE7 which runs directly the file in server may differ. – User 4.5.5 Mar 11 '13 at 07:04
  • What the error says, what is the message you are getting? – Sudip Pal Mar 11 '13 at 07:07
  • responseText:undefined ,XHR statusText:[object Error],textStatus:error,error: Access is denied.These are the alerts that i got for file when accessed from localhost in IE7 – User 4.5.5 Mar 11 '13 at 07:31
  • A quick check, change the url to local file and before that correct the URL, there should be https:// inseat of https:/ – Sudip Pal Mar 11 '13 at 07:52
  • That was a sample url to which my ajax method submits the params in post method and gets the session token. – User 4.5.5 Mar 11 '13 at 09:42
  • 2
    `localhost` is not `abc.com`, this is a duplicate of [Ways to circumvent the same-origin policy](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) – Quentin Mar 11 '13 at 09:42
  • sorry buddy, you are confusing lot...! :( – Sudip Pal Mar 11 '13 at 09:54
  • ok to clarify the things above is a html page with the javascript in which ajax post method has a URL(the URL there is not the exact one) which fetches session token on 'success' of ajax method.This html page in local disk when run on IE7 browser its working fine and returning 'success'.But when i deployed this html page on local server and then refer that filepath of server with localhost:8080 in IE7 ,the ajax method is not getting 'success' as return and no sessiontoken is dispalyed, instead error is returned from ajax method. what might be the problem. – User 4.5.5 Mar 11 '13 at 10:06
  • Yes. That's a security restriction to protect you from having your data on `abc.com` being stolen by JavaScript on Joe Random Site you are visiting. See the link to the duplicate above. – Quentin Mar 11 '13 at 11:38
  • so is there any way to get the data accessed from it securely. – User 4.5.5 Mar 11 '13 at 11:48
  • **See the link to the duplicate above** – Quentin Mar 11 '13 at 13:20

0 Answers0