P
P
Pavel Chuev2015-11-10 17:31:29
JavaScript
Pavel Chuev, 2015-11-10 17:31:29

How to perform some action if there is a request status in the array?

function TestFunc() {
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) {
            try {
                var data = JSON.parse(xhr.responseText);
            } catch(err) {
                console.log("JSON parse error:", err.message);
                console.log("Invalid JSON:", xhr.responseText)
                return;
            };
        }};
    xhr.open('GET', 'тут запрос на первый сервер' false);
    xhr.send();
}

The above code makes a request to the server several times per second and receives a response similar to this.
{"result":"kakie-to slova","id":false}
And sometimes I get such a response from the server
{"result":"ok","id":"19512591"}
. So.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-11-10
@alexey-m-ukolov

Um, what's the question?

if (data.id !== false)
{
  doStuff();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question