1

everyone. I am trying to use ajax to get data from server and it does not work. I got stacked on this problem for couple days and really have no idea how to handles. Could you point it out how can I solve the problem? Thanks

        function loadXMLDoc() 
        {
            user_input = document.getElementById('u_name').value;
            var url_s = url_seller + user_input;
            var url_b = url_bidder + user_input;
            var req = new XMLHttpRequest();
            req.onreadystatechange = function() 
            {
                if (req.readyState == 4 && req.status == 200) 
                {
                    var res = JSON.parse(req.responseText);
                }
            };
            req.open("GET", url_s, true);
            req.send();
        }       

I call this function using a button Submit

  • How do use get this variable `url_seller` and `url_bidder`? – Mawia HL Apr 19 '16 at 03:38
  • I get these two variable by define them outside the function. var url_bidder = "http://localhost:8090/Auction/getAuctionsBySeller.jsp?bidder="; – TurboCatEatsCarrot Apr 19 '16 at 03:43
  • Then define both the variables inside the function. And this [answer](http://stackoverflow.com/questions/500431/what-is-the-scope-of-variables-in-javascript) will help. Or you can define your variable as global outside the function. – Mawia HL Apr 19 '16 at 03:47
  • Then I got the same error I got before XHR failed loading: GET "http://localhost:8090/Auction/getAuctionsBySeller.jsp?seller=james" I can get Json data back by open this link in the browser – TurboCatEatsCarrot Apr 19 '16 at 03:53
  • 1
    add the complete code in the question. – Mawia HL Apr 19 '16 at 03:53
  • I solved the problem that was a stupid mistake. Thx for the help ! – TurboCatEatsCarrot Apr 20 '16 at 20:58

0 Answers0