HighDots Forums  

AJAX window.location.href.indexOf("http")==-1)

Javascript JavaScript language (comp.lang.javascript)


Discuss AJAX window.location.href.indexOf("http")==-1) in the Javascript forum.

Reply
 
Thread Tools Display Modes
  #1  
Old   
whisher@maktoob.com
 
Posts: n/a

Default AJAX window.location.href.indexOf("http")==-1) - 11-20-2006 , 05:37 PM






Hi.
Sorry to disturb you but I can't
figure out its use in this snippet
(Found in many scripts about Ajax)
function loadpage(page_request, containerid)
{
if (page_request.readyState == 4 && (page_request.status==200 ||
window.location.href.indexOf("http")==-1))
{
document.getElementById(containerid).innerHTML=pag e_request.responseText;
}
}
Can you enlighten me ?
Thanks in advance
Bye.




Reply With Quote
  #2  
Old   
shimmyshack
 
Posts: n/a

Default Re: AJAX window.location.href.indexOf("http")==-1) - 11-20-2006 , 08:20 PM






its in case you want to run the script locally.


Reply With Quote
  #3  
Old   
kday33@gmail.com
 
Posts: n/a

Default Re: AJAX window.location.href.indexOf("http")==-1) - 11-20-2006 , 08:49 PM



window.location.href.indexOf("http")==-1

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.


Reply With Quote
  #4  
Old   
Randy Webb
 
Posts: n/a

Default Re: AJAX window.location.href.indexOf("http")==-1) - 11-20-2006 , 09:24 PM



kday33 (AT) gmail (DOT) com said the following on 11/20/2006 8:49 PM:
Quote:
window.location.href.indexOf("http")==-1

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/


Reply With Quote
  #5  
Old   
Jonas Raoni
 
Posts: n/a

Default Re: AJAX window.location.href.indexOf("http")==-1) - 11-20-2006 , 11:14 PM



Randy Webb escreveu:
Quote:
kday33 (AT) gmail (DOT) com said the following on 11/20/2006 8:49 PM:
[...]
And if you are running it locally the readyState will never be 200.
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


Reply With Quote
  #6  
Old   
Richard Cornford
 
Posts: n/a

Default Re: AJAX window.location.href.indexOf("http")==-1) - 11-21-2006 , 03:51 AM



Jonas Raoni wrote:
Quote:
Randy Webb escreveu:
kday33 (AT) gmail (DOT) com said the following on 11/20/2006 8:49 PM:
[...]
And if you are running it locally the readyState will never be 200.

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.
Are you proposing that HTTP status 200 (OK) should be handled the same
way as 201 (Created), 204 (No Content) or 202 (Accepted)?

Richard.




Reply With Quote
  #7  
Old   
whisher@maktoob.com
 
Posts: n/a

Default Re: AJAX window.location.href.indexOf("http")==-1) - 11-21-2006 , 04:04 AM




Jonas Raoni ha scritto:

Quote:
Randy Webb escreveu:
kday33 (AT) gmail (DOT) com said the following on 11/20/2006 8:49 PM:
[...]
And if you are running it locally the readyState will never be 200.

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



Reply With Quote
  #8  
Old   
ASM
 
Posts: n/a

Default Re: AJAX window.location.href.indexOf("http")==-1) - 11-21-2006 , 05:23 AM



whisher (AT) maktoob (DOT) com a écrit :
Quote:
Hi.
Sorry to disturb you but I can't
figure out its use in this snippet

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'

Quote:
{
document.getElementById(containerid).innerHTML=pag e_request.responseText;
}
}

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date


Reply With Quote
  #9  
Old   
Jonas Raoni
 
Posts: n/a

Default Re: AJAX window.location.href.indexOf("http")==-1) - 11-21-2006 , 10:28 PM



Richard Cornford escreveu:
Quote:
Jonas Raoni wrote:
Are you proposing that HTTP status 200 (OK) should be handled the same
way as 201 (Created), 204 (No Content) or 202 (Accepted)?
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.


--
Jonas Raoni Soares Silva
http://www.jsfromhell.com


Reply With Quote
  #10  
Old   
shimmyshack
 
Posts: n/a

Default Re: AJAX window.location.href.indexOf("http")==-1) - 11-22-2006 , 04:02 AM







Quote:
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'm with you Jonas,

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.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.