473,804 Members | 3,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XMLHttpRequest Query/permissions

SE
Hi all,

Apologies if this has been done before.

I am trying to do some stuff with XMLHttpRequest in mozilla but no dice. I
have finally pared everything down to the minimum to see what is happening
with this script

-----------------------------------------------------
xmlhttp = new XMLHttpRequest( );
alert(xmlhttp);
// }
alert("Trying the test now");
xmlhttp.open("G ET", "test.txt",true );
xmlhttp.onready statechange=fun ction() {
if (xmlhttp.readyS tate==4) {
if (xmlhttp.status ==200) alert("URL Exists!");
else if (xmlhttp.status ==404) alert("URL doesn't exist!");
else alert("Status is "+xmlhttp.statu s);
}
}
xmlhttp.send(nu ll);
alert(xmlhttp.s tatus);
document.write( "Status is " + xmlhttp.status) ;
xmlhttp.send(nu ll);

--------------------------------------------------

The first alert box comes up telling me that xmlhttp is an object. The
second box telling me that it is about to try getting the file comes up,
THEN NOTHING!

I am running the script on an Apache server.

Any help gratefully received.

Thanks.

Steve

Sep 8 '05 #1
7 1892
"SE" <st***@ab.com > wrote in message
news:uG******** ********@fe2.ne ws.blueyonder.c o.uk...
Hi all,

Apologies if this has been done before.

I am trying to do some stuff with XMLHttpRequest in mozilla but no dice.
I
have finally pared everything down to the minimum to see what is happening
with this script

-----------------------------------------------------
xmlhttp = new XMLHttpRequest( );
alert(xmlhttp);
// }
alert("Trying the test now");
xmlhttp.open("G ET", "test.txt",true );
xmlhttp.onready statechange=fun ction() {
if (xmlhttp.readyS tate==4) {
if (xmlhttp.status ==200) alert("URL Exists!");
else if (xmlhttp.status ==404) alert("URL doesn't exist!");
else alert("Status is "+xmlhttp.statu s);
}
}
xmlhttp.send(nu ll);
alert(xmlhttp.s tatus);
document.write( "Status is " + xmlhttp.status) ;
xmlhttp.send(nu ll);

--------------------------------------------------

The first alert box comes up telling me that xmlhttp is an object. The
second box telling me that it is about to try getting the file comes up,
THEN NOTHING!


Why the last 3 lines of your script? Especially your second .send() is
curious.

--
Dag.
Sep 8 '05 #2
SE
Dag

Just trying to get anything to work at present. I can delete and test
however.

Steve
"Dag Sunde" <me@dagsunde.co m> wrote in message
news:T5******** ***********@jul iett.dax.net...
"SE" <st***@ab.com > wrote in message
news:uG******** ********@fe2.ne ws.blueyonder.c o.uk...
Hi all,

Apologies if this has been done before.

I am trying to do some stuff with XMLHttpRequest in mozilla but no dice.
I
have finally pared everything down to the minimum to see what is happening with this script

-----------------------------------------------------
xmlhttp = new XMLHttpRequest( );
alert(xmlhttp);
// }
alert("Trying the test now");
xmlhttp.open("G ET", "test.txt",true );
xmlhttp.onready statechange=fun ction() {
if (xmlhttp.readyS tate==4) {
if (xmlhttp.status ==200) alert("URL Exists!");
else if (xmlhttp.status ==404) alert("URL doesn't exist!");
else alert("Status is "+xmlhttp.statu s);
}
}
xmlhttp.send(nu ll);
alert(xmlhttp.s tatus);
document.write( "Status is " + xmlhttp.status) ;
xmlhttp.send(nu ll);

--------------------------------------------------

The first alert box comes up telling me that xmlhttp is an object. The
second box telling me that it is about to try getting the file comes up,
THEN NOTHING!


Why the last 3 lines of your script? Especially your second .send() is
curious.

--
Dag.

Sep 8 '05 #3


SE wrote:

I am trying to do some stuff with XMLHttpRequest in mozilla but no dice. I
have finally pared everything down to the minimum to see what is happening
with this script

-----------------------------------------------------
xmlhttp = new XMLHttpRequest( );
alert(xmlhttp);
// }
alert("Trying the test now");
xmlhttp.open("G ET", "test.txt",true );
xmlhttp.onready statechange=fun ction() {
if (xmlhttp.readyS tate==4) {
if (xmlhttp.status ==200) alert("URL Exists!");
else if (xmlhttp.status ==404) alert("URL doesn't exist!");
else alert("Status is "+xmlhttp.statu s);
}
}
xmlhttp.send(nu ll);
alert(xmlhttp.s tatus);
document.write( "Status is " + xmlhttp.status) ;
xmlhttp.send(nu ll);


As already said, the last three lines make no sense, creation, open,
onreadystatecha nge and the first send are all fine but then the object
has to asynchronously make the HTTP request and all further processing
has to happen in the onreadystatecha nge event handler so after the first
call to send there should be no more code, at least no code accessing
xmlhttp, let that simply do its work then.

The document.write call after the send might even kill anything,
depening on when the whole code is called, e.g. if you do that after
page load then that document.write call would overwrite the current
document.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 8 '05 #4
SE
Martin/Dag

I have killed the last three lines and made a couple of other changes and
it is working now. Thanks for your help. I will now get down to the real
programming!

Steve
"Martin Honnen" <ma*******@yaho o.de> wrote in message
news:43******** *************** @newsread4.arco r-online.net...


SE wrote:

I am trying to do some stuff with XMLHttpRequest in mozilla but no dice. I have finally pared everything down to the minimum to see what is happening with this script

-----------------------------------------------------
xmlhttp = new XMLHttpRequest( );
alert(xmlhttp);
// }
alert("Trying the test now");
xmlhttp.open("G ET", "test.txt",true );
xmlhttp.onready statechange=fun ction() {
if (xmlhttp.readyS tate==4) {
if (xmlhttp.status ==200) alert("URL Exists!");
else if (xmlhttp.status ==404) alert("URL doesn't exist!");
else alert("Status is "+xmlhttp.statu s);
}
}
xmlhttp.send(nu ll);
alert(xmlhttp.s tatus);
document.write( "Status is " + xmlhttp.status) ;
xmlhttp.send(nu ll);


As already said, the last three lines make no sense, creation, open,
onreadystatecha nge and the first send are all fine but then the object
has to asynchronously make the HTTP request and all further processing
has to happen in the onreadystatecha nge event handler so after the first
call to send there should be no more code, at least no code accessing
xmlhttp, let that simply do its work then.

The document.write call after the send might even kill anything,
depening on when the whole code is called, e.g. if you do that after
page load then that document.write call would overwrite the current
document.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Sep 8 '05 #5
"SE" <st***@ab.com > wrote in message
news:Wv******** *********@fe2.n ews.blueyonder. co.uk...
Martin/Dag

I have killed the last three lines and made a couple of other changes and
it is working now. Thanks for your help. I will now get down to the real
programming!


Good!

You can also make it cleaner/easier to read (IMO) by separating
the onreadystatecha nge function in a separate function:

var xmlhttp;

function getTest() {
xmlhttp = new XMLHttpRequest( );
xmlhttp.open("G ET", "test.txt",true );
xmlhttp.onready statechange = testCallback;
xmlhttp.send(nu ll);
}

function testCallback() {
if (xmlhttp.readyS tate==4) {
if (xmlhttp.status ==200)
alert("URL Exists!");
else if (xmlhttp.status ==404)
alert("URL doesn't exist!");
else
alert("Status is "+xmlhttp.statu s);
}
}

--
Dag.

Sep 8 '05 #6
Dag Sunde wrote:
SE wrote:
I have killed the last three lines and made a couple
of other changes and it is working now. Thanks for
your help. I will now get down to the real programming!


Good!

You can also make it cleaner/easier to read (IMO) by
separating the onreadystatecha nge function in a separate
function:

var xmlhttp;

function getTest() {
xmlhttp = new XMLHttpRequest( );
xmlhttp.open("G ET", "test.txt",true );
xmlhttp.onready statechange = testCallback;
xmlhttp.send(nu ll);
}

function testCallback() {
if (xmlhttp.readyS tate==4) {
if (xmlhttp.status ==200)
alert("URL Exists!");
else if (xmlhttp.status ==404)
alert("URL doesn't exist!");
else
alert("Status is "+xmlhttp.statu s);
}
}


It is an opinion that you won't maintain after you have thought about it
a bit.

Asynchronous XmlHttp requests may be concurrent, that is, a second may
be initiated before the completion of the first. If you use a single
globally scoped variable to hold a reference to an XmlHttp request
object then the initiation of the second request replaces the reference
to the first object. If this happens before the first request has fully
loaded its onreadystatecha nge handler will be reading the readyState of
the second request whenever the state of the first changes. This will
almost certainly mean that it never does whatever it was intended to do.
And in the event that coincidence does have it act (a readyState change
happens in the first object when the second object is already at
readyState 4) it will be acting upon the wrong XmlHttp request object.

Unfortunately the possibility of having the event handling function act
upon its own object through the use of the - this - keyword is rendered
non-viable by a bug in IE that prevents the correct resolution of the -
this - keyword in the context of the onreadystatecha nge handler.

This situation is normally coped with through the use of closures, and
so assigning an inner function to the event handler is normal and
sensible. Subject to that reference being freed after the completion of
the process to avoid circular references causing the IE memory leak
problem. But your global reference to the object leaves an un-freed
circular reference anyway (The function object refers to its scope
chain, its scope chain refers to the global object, the global object
refers to the XmlHttp request object (as the value of its xmlhttp
property), the XmlHttp request object refers back to the function object
(as the value of its onreadystatecha nge property)).

Richard.
Sep 9 '05 #7
"Richard Cornford" <Ri*****@litote s.demon.co.uk> wrote in message
news:df******** ***********@new s.demon.co.uk.. .
Dag Sunde wrote:
SE wrote:
I have killed the last three lines and made a couple
of other changes and it is working now. Thanks for
your help. I will now get down to the real programming!
Good!

You can also make it cleaner/easier to read (IMO) by
separating the onreadystatecha nge function in a separate
function:

<snipped It is an opinion that you won't maintain after you have thought about it
a bit.

Asynchronous XmlHttp requests may be concurrent, that is, a second may
be initiated before the completion of the first. If you use a single
globally scoped variable to hold a reference to an XmlHttp request
object then the initiation of the second request replaces the reference
to the first object. If this happens before the first request has fully
loaded its onreadystatecha nge handler will be reading the readyState of
the second request whenever the state of the first changes. This will
almost certainly mean that it never does whatever it was intended to do.
And in the event that coincidence does have it act (a readyState change
happens in the first object when the second object is already at
readyState 4) it will be acting upon the wrong XmlHttp request object.
That all depends on the context you use it in. As a programmer, you
know very well if you have designed your code so it is possible to
trigger a concurrent call (ie.behind a button), or if it does a one-shot
cleanup procedure in 'onunload'...

So I still maintain my opinion, but I should have mentioned the pitfalls
to the OP.

Unfortunately the possibility of having the event handling function act
upon its own object through the use of the - this - keyword is rendered
non-viable by a bug in IE that prevents the correct resolution of the -
this - keyword in the context of the onreadystatecha nge handler.

This situation is normally coped with through the use of closures, and
so assigning an inner function to the event handler is normal and
sensible. Subject to that reference being freed after the completion of
the process to avoid circular references causing the IE memory leak
problem. But your global reference to the object leaves an un-freed
circular reference anyway (The function object refers to its scope
chain, its scope chain refers to the global object, the global object
refers to the XmlHttp request object (as the value of its xmlhttp
property), the XmlHttp request object refers back to the function object
(as the value of its onreadystatecha nge property)).


This is all true, and it is a pity with the ie-bug. Because without that
bug, I could have it my way in all situations without the problems you
outline above.

--
Dag.
Sep 9 '05 #8

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

Similar topics

1
2749
by: Phil Powell | last post by:
Here is the scope of what I need to do; want: enrollment_year allowed (even if null) all of ica criteria:
3
1840
by: RCarter | last post by:
Hi, I have to write a web program (not a web site) and I was exploring all possibilities. When I found XMLHttpRequest I decided to use it. I'm interesting also in DOM, and I formuled this idea of a PHP framework: for every page of the program: - an XML file where there are all the static parts, and where the dynamic part have to go (after a DB query, etc.) you put something like
18
7340
by: William | last post by:
I have the following javascript function that updates a scroll_list and sends the updated entry (with its index) to a server script ( i.e. http://mkmxg00/cgi/confirmUpload.pl ) for further processing: function saveText( scroll_list, t_area, listToBeUpdated ) { scroll_list.options.text = t_area.text; scroll_list.options.value= t_area.value; var req; var url = "http://mkmxg00/cgi/confirmUpload.pl";
1
1490
by: dave | last post by:
I want to design/develop an windows application that can query multiple websites (XmlHttpRequest), call number of 3rd party external webservices (SOAP) and parse/process the data and display it to the user. Ideally this would have been developed as a website, but due to crosss doman limitation on XmlHttpRequest, I am thinking of developing it as an windows application.
1
6793
by: dave | last post by:
I want to design/develop an windows application (C#) that can query multiple websites (XmlHttpRequest), call number of 3rd party external webservices (SOAP) and parse/process the data and display it to the user. Ideally this would have been developed as a website, but due to crosss doman limitation on XmlHttpRequest, I am thinking of developing it as an windows application.
10
11337
by: test | last post by:
Hi, I want to asynchronously recieve large amount of data using XMLHTTPRequest. If it is possible, I would like to make a progress bar to show the user how the process is going. According to the information I found, the object can only be in five states (shown below). Is it possible to see how much data has already been recieved when the object is in state 3?
5
2411
by: Peter Michaux | last post by:
Hi, The FAQ correctly says the following: "Mozilla (NN6.2+, Firefox, Ice Weasle etc), Opera 7.6+, Safari1.2+, the Windows version of IE versions 5+, and some other browsers provide the XML HTTP Request object." In my haze of testing yesterday it seems that NN6.1 provides an non-functional XMLHttpRequest object and NN6.2 XMLHttpRequest object
8
2161
rpnew
by: rpnew | last post by:
HI, I'm working with PHP/MySql... on one page i've used this XMLHttprequest object. Now i'm developing the system on FC4/FireFox.. on my machine it works fine but if i try to access it from another PC then following happens.... From another PC which has Windows XP/FireFox/IE with firefox(on my machine it works fine) it shows the whole script as an output and not the result i wanted..... with IE it does nothing...
0
10558
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10302
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
10069
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...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
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
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
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
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2975
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.