Error

0 Norbert Korom · June 29, 2015
Anybody found what the hell is the problem with this code?
I copy the code, but i always got the alert error in the browser. I seen the comments on youtube where many user wrote something is wrong with the code.... are you found what?
Thanks

Post a Reply

Replies

Oldest  Newest  Rating
0 Jagdeep Matharu · June 29, 2015
where is the code?
0 Norbert Korom · June 30, 2015
Oh sorry, i posted my comment under the tutorial, but it create a new forum post maybe:) sry, i'm new here
So, my question posted aboout this code :
https://www.thenewboston.com/videos.php?cat=61&video=19315
I not found the code, just the tutorial.
I red the comment on the youtube, but isn't good answer there.

Code is here. The red line give me an error in the browser.
 - Uncaught TypeError: Cannot read property 'documentElement' of null

Code:
function process(){
      console.log(" function process() start ");
        if (xmlHttp.readyState == 0 || xmlHttp.readyState == 4) {
          console.log(" process() xmlHttp.readyState == 0 || 4 ");
           
            var food = encodeURIComponent (document.getElementById("userInput").value);
            console.log(" var food = encodeURIComponent (document.getElementById(\"userInput\").value);");
          
            xmlHttp.open("GET" , "php/foodstore.php?food="+food , true);
          
            xmlHttp.onreadystatechange = handleServerResponse;
            xmlHttp.send(null);
          
        }else{
          
            setTimeOut ('process()' , 1000);
            console.log("process() - else");
        }

    }

    function handleServerResponse() {

      if (xmlHttp.readyState < 4)  {                      // while waiting response from server
          document.getElementById('underUserInput').innerHTML = "Loading...";
        
      else if (xmlHttp.readyState == 4)  {                      // while waiting response from server
          document.getElementById('underUserInput').innerHTML = "Loading...";
        
          if (xmlHttp.status == 200 && xmlHttp.status < 300) {
                    xmlResponse = xmlHttp.responseXML;

                    xmlDocumentElement = xmlResponse.documentElement;
                    message = xmlDocumentElement.firstChild.data;
                    document.getElementById('underUserInput').innerHTML = '<span style="color:blue"> ' + message + '</span>';
                    setTimeOut ('process()' , 1000);

                }
            }else{
                alert('Something went wrong!');
            }
    }


Thanks
  • 1

Javascript

107,288 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators