AJAX on local computer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alexander111
    New Member
    • Jul 2010
    • 3

    AJAX on local computer

    I set Tomcat to be run on 80 port and have an jsp that returns html. Why doesn't it work? It doesn't even turn on alert 2. What's matter. Please, tell me.

    Code:
    <html>
    
    <head>
    
    <script type="text/javascript">
    
    
    
    
    function getCustomerInfo() 
    {
    	alert("1!");	
    var request = new XMLHttpRequest();
    
         var a = document.getElementById("aa").value;
    
         var url = "http://localhost/MyProject/index.html";
    
         request.open("GET", url, true);
         request.onreadystatechange = updatePage;
         request.send();
    
    alert("2!");
    
    }
    
    function updatePage() 
    {
        document.getElementById("myDiv").innerHTML="aaa";
    }
    
    
    </script>
    
    </head>
    
    <body>
    
    <div id="myDiv"><h2>Let AJAX change this text</h2></div>
    <button type="button" onclick="getCustomerInfo()">Change Content</button>
    
    
    </body>
    
    </html>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Try using a relative URL instead of an absolute one.

    Also note that the second alert should be in the callback function (updatePage) if you want to test because it's asynchronous.

    Comment

    • Alexander111
      New Member
      • Jul 2010
      • 3

      #3
      Thanks fo reply!
      But.. I tried everything. E.g. "index.html","\ (/)index.html", "\MyProject\ind ex.html", "MyProject\inde x.html", "localhost\MyPr oject..." et cetra... But no...

      And, I thought, the function should be work to the end. I send reqest by object.send() and then it should show me an alert, but no. I think it can't pass it 'till second alert, but why....

      Comment

      • Alexander111
        New Member
        • Jul 2010
        • 3

        #4
        Well, thank you , acoder , for the answer!
        I've just figured it out. The problem was - string with "var a=..."

        Comment

        Working...