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

Synchronous XMLHttpRequest blocks earlier performed functions.

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 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 1436
dmjpro
2,476 2GB
Welcome to TSDN.

where u putting the test Loading
just send that code .....
May 15 '07 #2
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
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
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. ...
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...
2
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. ...
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: 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...
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...
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...
0
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...

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.