By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,474 Members | 1,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,474 IT Pros & Developers. It's quick & easy.

XMLHttpRequest() completion condition?

P: n/a
I came across something I'm unfamiliar with -- there's an added check
for window.location.href.indexOf("http")==-1 to see if the
XMLHttpRequest send() completed, i.e.,

if (page_request.readyState == 4 && (page_request.status==200 ||
window.location.href.indexOf("http")==-1))

Does anyone know why this is done or which browser this (kludge?) is
meant for?

Dec 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
robocoder said the following on 12/11/2005 9:57 PM:
I came across something I'm unfamiliar with -- there's an added check
for window.location.href.indexOf("http")==-1 to see if the
XMLHttpRequest send() completed, i.e.,

if (page_request.readyState == 4 && (page_request.status==200 ||
window.location.href.indexOf("http")==-1))

Does anyone know why this is done or which browser this (kludge?) is
meant for?


More than likely it is to prevent the page from being executed locally
instead of from a server. Without seeing the entire script in context,
it is impossible to tell why that check is there though. It should have
nothing to do with the HTTPRequest though unless it is trying to find
the generic 404 error message page which it wouldn't be executing in to
start with. Post the entire snippet or a URL. The URL being preferable
to where it is used at.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 12 '05 #2

P: n/a
VK

robocoder wrote:
I came across something I'm unfamiliar with -- there's an added check
for window.location.href.indexOf("http")==-1 to see if the
XMLHttpRequest send() completed, i.e.,

if (page_request.readyState == 4 && (page_request.status==200 ||
window.location.href.indexOf("http")==-1))

Does anyone know why this is done or which browser this (kludge?) is
meant for?


This is done for IE to debug AJAX locally (from your harddrive). For
file:\\ protocol status is always 0 not 200. When deploying a
ready-to-use script on the server the last check can be safely removed.

Dec 12 '05 #3

P: n/a
On 2005-12-12, robocoder <an*********@hotmail.com> wrote:
I came across something I'm unfamiliar with -- there's an added check
for window.location.href.indexOf("http")==-1 to see if the
XMLHttpRequest send() completed, i.e.,

if (page_request.readyState == 4 && (page_request.status==200 ||
window.location.href.indexOf("http")==-1))

Does anyone know why this is done or which browser this (kludge?) is
meant for?


looks like it's there so the developer can load the page from a disk file
without it giving errors.

Bye.
Jasen
Dec 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.