473,795 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getEle mentById('show1 ');
if (window.XMLHttp Request) {
req = new XMLHttpRequest( );
} else if (window.ActiveX Object) {
req = new ActiveXObject(" Microsoft.XMLHT TP");
}
req.onreadystat echange = function() {
if (req.readyState == 4 && req.status == 200) {
element.innerHT ML = req.responseTex t;
}
}
req.open("POST" , 'response.php', true);
req.setRequestH eader("Content-type",
"applicatio n/x-www-form-urlencoded");
req.send(null)
}
function testS () {
var element = document.getEle mentById('show2 ');
if (window.XMLHttp Request) {
req = new XMLHttpRequest( );
} else if (window.ActiveX Object) {
req = new ActiveXObject(" Microsoft.XMLHT TP");
}
req.onreadystat echange = function() {
if (req.readyState == 4 && req.status == 200) {
element.innerHT ML = req.responseTex t;
}
}
req.open("POST" , 'response.php', false);
req.setRequestH eader("Content-type",
"applicatio n/x-www-form-urlencoded");
req.send(null)
}
</script>
<span id="show1">sho w 1</span><br>
<span id="show2">sho w 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 2088


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.getEle mentById('show2 ');
if (window.XMLHttp Request) {
req = new XMLHttpRequest( );
} else if (window.ActiveX Object) {
req = new ActiveXObject(" Microsoft.XMLHT TP");
}
req.onreadystat echange = function() {
if (req.readyState == 4 && req.status == 200) {
element.innerHT ML = req.responseTex t;
}
}
req.open("POST" , 'response.php', false);
req.setRequestH eader("Content-type",
"applicatio n/x-www-form-urlencoded");
req.send(null)


Don't use onreadystatecha nge 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
3419
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 method returns immediately, and the callback function is called shortly thereafter... virtually immediately. I want to find a way to simplify my code by finding a way to simulate synchronous behavior for those functions. It's a little awkward...
9
17997
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 write "0" or "1" with a "response.write" method. The problem that I have is when I try this example with Synchronous mode. If I change the function sendNum with: xmlhttp.open("GET",url,false);
5
20090
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 with Firefox,but with IE6 the onFailure never gets called and the request never completes. My code: var ajaxReq = new Ajax.Request( url, {method: 'post', parameters:
2
6301
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 called .. (it does mean that State is not changing ..) <script> var req = new XMLHttpRequest(); req.open('GET', '_temp_delete.html', false);
5
15512
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 mode, it sounds as if a thread retrieves the data from the supplied URL and the JS function that called the open() and send() methods continues on. Where as using Synchronous mode the method that called open() and send() waits until the data from...
3
1450
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 the http-request starts. The strange thing here is that this "loading..." text is not visible on the page, but its method is performed though. If I place an "alert('something')" in between I do see the "loading..." on the page before the alert is...
6
8635
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 tried, including my conclusions/assumptions (which i'll happily be corrected on if it solves my problem!): The requirement not to use a proxy means I can't use the synchronous
2
1388
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 code is working properly on Internet Explorer,But firefox is not sending request to another server
1
1836
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 not sending request to a page which has another domain
0
9672
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...
0
10436
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...
0
10213
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
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
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
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
5436
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...
1
4113
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
3
2920
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.