Xmlhttprequest - Blank Answer

Asked

Viewed 54 times

2

I have a file on the server that, if you find the login and password informed, returns 1 or 0 if nothing is found. However, I am unable to receive this information using XMLHttpRequest. In PHP, I use echo (json_encode($)) to pass the value, but do not know how to take this value.

Here is my Javascript:

function logar()
{
    var request = new XMLHttpRequest();
    var url = "http://clleyton.hostoi.com/form_login.php/?login=" + document.getElementById("login").value + "&senha=" + document.getElementById("senha").value;
    console.log(url);
    request.open("GET", url, true);
    request.onreadystatechange = function() {
        if (request.readyState == 4)
        {
            if (request.status == 200 || request.status == 0)
            {

                console.log(request.responseText);
                console.log(request.response);
            }
        }
    }

}
  • There seems to be a URL formation error: var url = "...hostoi.com/form_login.php/?login="... Probably what you want to use is form_login.php?login try to get the /

1 answer

0

I confess that I have no experience with Xmlhttprequest and I have no way to give you an exact answer on how to solve the problem the way you need. But I recommend using fetch for communication between client <-> server.

Simply you will be able to request (GET) that needs and control the response through Promises.

I know it may seem too much to use a polyfill for your problem, but in general I think it is valid to evaluate that it is a new technology with native specification in javascript. You will only be anticipating what a day will be common in everyday life. Much more elegant and simple than this XMLHttpRequest ;)

Browser other questions tagged

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