473,783 Members | 2,577 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Synchronous XMLHttpRequest blocks earlier performed functions.

3 New Member
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('somethi ng')" in between I do see the "loading... " on the page before the alert is popping up.

How can I achieve to see the loading before the request instead of after the response of the request?

Thanks in advance...

Harold
May 15 '07 #1
3 1449
dmjpro
2,476 Top Contributor
Welcome to TSDN.

where u putting the test Loading
just send that code .....
May 15 '07 #2
Haroldp
3 New Member
When clicked on the row element this must be performed:

Expand|Select|Wrap|Line Numbers
  1. row.onclick = function()
  2.  (
  3.  
  4.         LoadingData("LoadingTable");
  5.         passData = "SessionId=" + SessionId + "&Level=" + "User");
  6.         var XMLResponse = SynchCall("wSetMainSelection", passData);
  7.         OnResponse(XMLResponse.documentElement.childNodes[0].data);
  8.  }

The funcion SynchCall is as follows:

Expand|Select|Wrap|Line Numbers
  1. function SynchCall(method, passData)
  2. {
  3.  
  4.    //alert("no matter what");
  5.  
  6.     url = "http://" + location.host + "/project/webservice/Access.asmx/" + method;
  7.     if (window.XMLHttpRequest) 
  8.     {
  9.         xmlhttp=new XMLHttpRequest();
  10.     } 
  11.     else 
  12.     {
  13.         xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  
  14.     }  
  15.     if (xmlhttp) 
  16.     {    
  17.         xmlhttp.open("POST", url, false);
  18.         xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  19.         xmlhttp.send(passData);
  20.         return xmlhttp.responseXML;
  21.     } 
  22.     else 
  23.     {
  24.         alert("Not able to create HTTP request");
  25.     }
  26. }
You see that the alert is commented out. If I enable it, the LoadingData function will be performed.
May 15 '07 #3
Haroldp
3 New Member
This code is more clear:

When clicked on the row element this must be performed:

Expand|Select|Wrap|Line Numbers
  1. row.onclick = function()
  2.  (
  3.  
  4.         LoadingData("LoadingDiv");
  5.         passData = "SessionId=" + SessionId + "&Level=" + "User");
  6.         var XMLResponse = SynchCall("wSetMainSelection", passData);
  7.         OnResponse(XMLResponse.documentElement.childNodes[0].data);
  8.  }
  9.  
  10. LoadingData(div)
  11. {
  12.   document.getElementById(div).innerHTML = "Loading...";
  13. }
  14.  

The function SynchCall is as follows:

Expand|Select|Wrap|Line Numbers
  1. function SynchCall(method, passData)
  2. {
  3.  
  4.    //alert("no matter what");
  5.  
  6.     url = "http://" + location.host + "/project/webservice/Access.asmx/" + method;
  7.     if (window.XMLHttpRequest) 
  8.     {
  9.         xmlhttp=new XMLHttpRequest();
  10.     } 
  11.     else 
  12.     {
  13.         xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  
  14.     }  
  15.     if (xmlhttp) 
  16.     {    
  17.         xmlhttp.open("POST", url, false);
  18.         xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  19.         xmlhttp.send(passData);
  20.         return xmlhttp.responseXML;
  21.     } 
  22.     else 
  23.     {
  24.         alert("Not able to create HTTP request");
  25.     }
  26. }
The LoadingData function will be performed always. You see that the alert is commented out. If I enable it the text "Loading... " will be shown.
May 15 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3807
by: Brad | last post by:
A long-time JScript/IE programmer friend of mine shared a technique with me recently that puzzles me. He has a series of functions that perform POSTs, with each function returning a dummy value. He has a dummy variable in the calling code to catch it. He said that by both returning and catching this dummy value, the POSTs perform synchronously, whereas if there were no values caught in the calling code, they would perform asychronously....
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
17996
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);
2
2087
by: duncansinclair | last post by:
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) {
2
6300
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
2679
by: db2admin | last post by:
hello, admin guide says that pool_data_p_reads - pool_async_data_reads will give me number of physical reads that were performed synchronously (that is, physical data page reads that were performed by database manager agents). I assume then pool_data_p_reads should give total value of all reads ( synchronous + asynchronous ) i see values for pool_async_data_reads more than pool_data_p_reads in
5
15510
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...
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
3
1444
by: GaryDean | last post by:
I have just been through the docs on the Data Access Application blocks and it seems that they complicate things more than make things simple. To me it seems that there is nothing more simple and straight forward than writing simple stored procedures and executing them from .net code using easy to understand connection strings. I'm looking for opinions here from those that have used these tools. Am I missing something? --
0
10147
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
10083
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
9946
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
8968
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...
0
6737
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
5379
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
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
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.