XMLHttpRequest() completion condition?

R

robocoder

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?
 
R

Randy Webb

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.
 
V

VK

robocoder said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top