Ito Ito - 6 months ago 21
Ajax Question

XMLHttpRequest.response really null or not

Making AJAX call to a non-existent database element. Then the handler looks like this:

if (xhr.readyState === 4 && xhr.status === 200 && xhr.response !== null) {
console.log('response type is ' + typeof xhr.response); // string
console.log('response is ' + xhr.response); // null
// rest of the handler//

The question is, why my handler is executing the block (it always goes to console and log string and null), if i stated to do it only if response is not null ?


Well, if it's really logging

response type is string
response is null

...then clearly the response is the string "null".