473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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

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.

Nov 20 '06 #1
11 14598
its in case you want to run the script locally.

Nov 21 '06 #2
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.

Nov 21 '06 #3
kd****@gmail.com said the following on 11/20/2006 8: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.
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/
Nov 21 '06 #4
Randy Webb escreveu:
kd****@gmail.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
Nov 21 '06 #5
Jonas Raoni wrote:
Randy Webb escreveu:
>kd****@gmail.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.
Nov 21 '06 #6

Jonas Raoni ha scritto:
Randy Webb escreveu:
kd****@gmail.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.

Nov 21 '06 #7
ASM
wh*****@maktoob.com a écrit :
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'
{
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
Nov 21 '06 #8
Richard Cornford escreveu:
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
Nov 22 '06 #9
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.

Nov 22 '06 #10
Jonas Raoni said the following on 11/20/2006 11:14 PM:
Randy Webb escreveu:
>kd****@gmail.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,
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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 22 '06 #11
This script was part of a library, Jonas and I are making the point
that as AJAX matures the complexity of this part of the js that checks
for response codes should start reflect the full structure of the RFC
where 200 _isn't_ always what you want or what you get.

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.

Nov 22 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: saiho.yuen | last post by:
Hi, Is anyone know what is the difference between Location.href and Window.location.href Thanks you very much:) Saiho
2
by: Brvsra | last post by:
Javascript Experts, I know very little about javascript and could use someone's help. I have created a function to send an email, listed below is the function. The function works fine, with...
1
by: Valentin Botog | last post by:
why window.location.href or window.location javascript functions doesn't work on mac browsing IE *** Sent via Developersdex http://www.developersdex.com ***
4
by: Jeff Paffett | last post by:
I'm writing a file manager application using Ajax techniques and the client wants to be able to bookmark file searches. I send the search request to a remote server using a XMLHttpRequest and then...
3
by: André | last post by:
Hi, What's the code in VB.net for "window.location.href" in javascript ? Thanks André
2
by: pbd22 | last post by:
Hi. I have built a site with tabs-based navigation as a pretty major component. The tabs use window.location.href to understand where the user is and displays the appropriate tabs accordingly....
1
by: Mihania | last post by:
Permission denied exception is fired in IE6 on line(9) during the following actions . (1)<html> (2)<head> (3) <title>Simple :: documentDomain :: Cars</title> (4)</head> (5)<body> (6) ...
1
risk32
by: risk32 | last post by:
I seem to have a problem. I'm trying to use the window.location.href code to direct a webpage through an IP address. I receive no errors through IE, but the location is wrong. It's still trying to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.