I haven't seen this before, but this part of the statement will be true
if the url of the requesting page does not contain the string "http".
Shimmyshack is probably right, because if you're running the script in
an HTML page locally on your computer, then it won't have "http" in the
URL, it'll be something like "C:/..." whatever.
And if you are running it locally the readyState will never be 200.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Also checking for the constant "200" isn't nice in my opinion, because
what defines the status is just the first digit of the code, the others
act as a kind of sub-status.
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Are you proposing that HTTP status 200 (OK) should be handled the same
way as 201 (Created), 204 (No Content) or 202 (Accepted)?
Richard.
Thanks a lot buddies.
It's quite clear to me.
But I also found this Ajax library
and to check the status it's use
a boolean var.
function XHConn()
{
var xmlhttp, bComplete = false;
try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) { try { xmlhttp = new XMLHttpRequest(); }
catch (e) { xmlhttp = false; }}}
if (!xmlhttp) return null;
this.connect = function(sURL, sMethod, sVars, fnDone)
{
if (!xmlhttp) return false;
bComplete = false;
sMethod = sMethod.toUpperCase();
try {
if (sMethod == "GET")
{
xmlhttp.open(sMethod, sURL+"?"+sVars, true);
sVars = "";
}
else
{
xmlhttp.open(sMethod, sURL, true);
xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
xmlhttp.onreadystatechange = function(){
//HERE -------------!bComplete-------------
if (xmlhttp.readyState == 4 && !bComplete)
{
bComplete = true;
fnDone(xmlhttp);
}};
xmlhttp.send(sVars);
}
catch(z) { return false; }
return true;
};
return this;
}
var myConn = new XHConn();
if (!myConn) alert("XMLHTTP not available. Try a newer/better
browser.");
var fnWhenDone = function (pXML) { alert(pXML.responseText); };
myConn.connect("test.txt", "GET","",fnWhenDone);
Is it the same case or not ?
Bye.
> function loadpage(page_request, containerid)
> {
> if (page_request.readyState == 4 && (page_request.status==200 ||
> window.location.href.indexOf("http")==-1))
if XMLHttpRequested file is ready ( =4 )
and
- all was OK on server ( =200)
- or file actually displayed *is* from http
in this case : all was not OK
and error (responseText) will be shown in div 'contaierid'
> {
> document.getElementById(containerid).innerHTML=page_request.responseText;
> }
> }
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
No, you handle them the way you want, I just said that if the response
doesn't have the status 200, it doesn't mean that it failed.
I often use 204 (no content) to quickly stop the browser in its tracks
whilst still having a client-server interaction, and 206 (partial
content) to add to previously buffered output from the server.
At the moment many of the checks and balances buried inside the
libraries only reflect a basic implementation and imho as ajax gets
more mature, we will see these libraries reflecting the full rfc's in
many of these areas, such as HTTP.
Then what *should* you be checking for? 2* ?
> because what defines the status is just the first digit of the code, the others
> act as a kind of sub-status.
And in this case, you want 200 and 200 only.
For instance, a 304 header check could be implemented here, if
somewhere else in the code caching is being used, so that you get a
benefit in using AJAX, if each time you click a button you get the same
200 with response body, this is hardly using AJAX to its full, however
if you have implemented some form of caching, then the headers sent
could be a bit more advanced and the codes back could save you time in
both receiving the data, parsing it and rendering it.
I would personally prefer it if libraries didnt just assume that 200 is
the only code out there that is useful to AJAX.