Doubt with xhr.Answer

Asked

Viewed 23 times

0

I have the following Javascript code:

function load(){
    var validationEmail = Email.value;
    var validaationCode = Code.value;

    var json = JSON.stringify({"userName": validationEmail, "codeCustomer": validaationCode});
    var url = "http://minha url";
    var xhr = new XMLHttpRequest();

    xhr.onreadystatechange = function(){
         if (xhr.readyState === 4) {
             console.log(xhr.response);

             if(xhr.response.value != false){

                console.log("kkkkkkk");
                document.getElementById("rootSingUp").innerHTML = loadSingUpPG1();
             }
        }
    }

    xhr.open("POST",url,true);
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.send(json);
}

This code is generating a JSON and sending it to my web service and with xhr.Answer if I’m getting the return of this request.

In the first IF, when I give console.log(xhr.Response) he returns me true or false correctly.

but when I try to run the second if it doesn’t even enter that second condition

  • has how you show an image of the result of console.log(xhr.Response); ?

  • I advise you to use a library that makes your life easier. If not you can look at the Chrome developer tab and see the result. value will only be available if Voce returns an appropriate contenttype. https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/response

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.