473,769 Members | 3,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_r equest, containerid)
{
if (page_request.r eadyState == 4 && (page_request.s tatus==200 ||
window.location .href.indexOf(" http")==-1))
{
document.getEle mentById(contai nerid).innerHTM L=page_request. responseText;
}
}
Can you enlighten me ?
Thanks in advance ;)
Bye.

Nov 20 '06 #1
11 14653
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.co m 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.javas cript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 21 '06 #4
Randy Webb escreveu:
kd****@gmail.co m 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.co m 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.co m 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.XMLHT TP"); }
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.toUpper Case();

try {
if (sMethod == "GET")
{
xmlhttp.open(sM ethod, sURL+"?"+sVars, true);
sVars = "";
}
else
{
xmlhttp.open(sM ethod, sURL, true);
xmlhttp.setRequ estHeader("Meth od", "POST "+sURL+" HTTP/1.1");

xmlhttp.setRequ estHeader("Cont ent-Type","applicat ion/x-www-form-urlencoded");
}
xmlhttp.onready statechange = function(){
//HERE -------------!bComplete-------------
if (xmlhttp.readyS tate == 4 && !bComplete)
{
bComplete = true;
fnDone(xmlhttp) ;
}};
xmlhttp.send(sV ars);
}
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.resp onseText); };

myConn.connect( "test.txt", "GET","",fnWhen Done);
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_r equest, containerid)
{
if (page_request.r eadyState == 4 && (page_request.s tatus==200 ||
window.location .href.indexOf(" http")==-1))
if XMLHttpRequeste d 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.getEle mentById(contai nerid).innerHTM L=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
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

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

Similar topics

3
50427
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
872
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 one exception. When the function is passed, the popup screen only displays the first part of the querystring. The email address returns: http://server.something.asp?Test=1 Should return something like this:
1
1791
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
13087
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 write the search string to a # URL, either using window.location.href or window.location.hash. This works fine with no problems in IE and Firefox and works OK in Safari, except the browser goes into a permanent page loading state as soon as I...
3
7292
by: André | last post by:
Hi, What's the code in VB.net for "window.location.href" in javascript ? Thanks André
2
3616
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. I have recently learned about the sessionstate properties of ASP.NET 2.0 and am trying to user cookieless navigation. This makes a mess of the current URL and, as a result, window.location.href is pretty useless as a way to tell the tabs what to...
1
7016
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) <script> (7) var fake = window.location;
1
4487
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 put it through a local drive on my computer instead of the IP address I'm trying to forward to. Here's what I have: (I left the IP as 0's for the sake of my own protection) <input type="checkbox" id="forgot" value="Forgot Password?"...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9994
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.