Strange behaviour of xmlhttprequest
Posted: 2018-05-27, 14:25
This snippet:
works absolutely fine. But replace the url with "http://rawrtacular.com/bataneart" - and the request times out. Typing the url in the browser window without the '/' at the end works fine. Having said which it grows a trailing / in the process and the console says this:
so maybe the question should be why my XMLHttpRequest isn't behaving the same as the browser, and what should I do?
Addendum: I looked at the value of evt in the timeout and it has had the '/' appended to the responseURL.
Code: Select all
const url = "http://rawrtacular.com/bataneart/";
const xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open("GET", url);
xmlHttpRequest.ontimeout = evt => { console.log("timed out", evt, url) };
xmlHttpRequest.onabort = evt => { console.log("aborted", evt, url) };
xmlHttpRequest.onerror = evt => { console.log("error", evt, url) };
xmlHttpRequest.onload = evt => { console.log("complete", evt, url) };
xmlHttpRequest.timeout = 10000;
xmlHttpRequest.send();
Code: Select all
GET http://rawrtacular.com/bataneart [HTTP/1.1 301 Moved Permanently 250ms]
GET http://rawrtacular.com/bataneart/ [HTTP/1.1 200 OK 250ms]
Addendum: I looked at the value of evt in the timeout and it has had the '/' appended to the responseURL.