473,324 Members | 2,268 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,324 software developers and data experts.

Synchronous request in Firefox not working

The following code works in IE, but in Forefox (1.0.7 & 1.5) the
Asyncronous function (testA) works fine but the Synchronous one (testS)
does not. It just doesn't work & I get no errors.

Anybody have an idea why?

<script>
function testA () {
var element = document.getElementById('show1');
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200) {
element.innerHTML = req.responseText;
}
}
req.open("POST", 'response.php', true);
req.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
req.send(null)
}
function testS () {
var element = document.getElementById('show2');
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200) {
element.innerHTML = req.responseText;
}
}
req.open("POST", 'response.php', false);
req.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
req.send(null)
}
</script>
<span id="show1">show 1</span><br>
<span id="show2">show 2</span><br><br>
<input type="button" value="Test Async" onClick="testA();">
<input type="button" value="Test Sync" onClick="testS();">

Dec 2 '05 #1
2 2063


du************@gmail.com wrote:
The following code works in IE, but in Forefox (1.0.7 & 1.5) the
Asyncronous function (testA) works fine but the Synchronous one (testS)
does not. It just doesn't work & I get no errors.

Anybody have an idea why? function testS () {
var element = document.getElementById('show2');
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200) {
element.innerHTML = req.responseText;
}
}
req.open("POST", 'response.php', false);
req.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
req.send(null)


Don't use onreadystatechange if you want to do synchronous stuff, put
the code to deal with the response after the send call, that synchronous
call is blocking until the response comes and your statements after the
send call are executed and can deal with status, responseText etc.
At least that should solve the problem I think.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 2 '05 #2
Works like a charm.

Thanks Martin

Dec 2 '05 #3

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

Similar topics

1
by: Chris | last post by:
Hi. I have a ibrary I'm trying to use via javascript within IE. This library uses an asynchronous model where I call into a function and pass it a callback function as one of its arguments. My...
9
by: David | last post by:
Hello I'm testing the XMLHttpRequest object in Firefox and IE. The code below works well in IE and Firefox. It shows "1" when the string is a number and "0" when not. The page aspxTest.aspx only...
5
by: dougwig | last post by:
I'm trying to handle the scenario where a user's session times out and and their ajax request triggers a redirection by the webserver (302 error?). I'm using Prototype 1.4 and the my works great...
2
by: Prasad | last post by:
Hi all! I am trying to access a page through Synchronous Ajax request in mozilla firefox I could not get the response .. After the requset is sent , "onreadystatechange" function is not being...
5
by: HugeBob | last post by:
Hi All, I've got a question about Asynchronous vs Synchronous mode with the XMLHttpRequest object. What are the ramifications of using one mode vs the other? If the script uses Asynchronous...
3
by: Haroldp | last post by:
Because I need to be sure that an Http Request is finished before other requests can be done I am using a synchronous XML Http Request. I want to show the text "loading..." on the page before...
6
by: Simon | last post by:
Hi All, An experiment i'm doing requires requires a synchronous cross-domain request, without using a proxy. I wondered if anyone had any ideas to help me achieve this. Below is what I have...
2
by: waqasahmed996 | last post by:
hi when i use ajax for sending a request on another server then it is not working in firefox. my code is var url="http://www.example.php" url=url+"?m="+m url=url+"&sid="+Math.random() this...
1
by: waqasahmed996 | last post by:
hi i am trying to send an information to a page which is on another server. var url="http://www.example/.php" this request is working properly on IE but not working on firefox firefox is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.