Support Forum Softcomplex logo
About Us  | Services  | Download  | Order  | Support  | |
| Search | Today's Posts | Stats | Board Rules | Not logged in [ Login | Register ]
go to bottom
Last active: Never

Printable Version | Subscribe | Add to Favourites   Post new thread
Author: Subject: How to make the JS wait !!
Khaled
Junior Member

Posts: 4
Registered: 3/19/2007
Location: Riyadh
Member Is Offline
posted on 3/19/2007 at 01:09 PM
How to make the JS wait !!


I'm developing AJAX application.
From JS, I call the server side program and expecting a result.

I want the JS to wait till the result is returned from server.

When I use alert(). It works very good and the JS and HTML are waiting. but i dont want to use alert()

Is there any other way to make the JS wait??
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 3/19/2007 at 03:59 PM

You can submit the request to the server side and exit the routine that did that or initiate the watchdog timer.
In the server response after the data, you can insert the JavaScript code that calls the data processing routine in main application.

Say in your main application you have functions submitData(..) and processData(..).
submitData(..) sends the request to the server side via iFrame. In the response you return:

Code:

<html>
... skipped ...

<script language="JavaScript">
var NEWDATA = ... skipped ...;
parent.processData(NEWDATA);
</script>

... skipped ...
</html>


this guarantees that the data is ready by the time you call the processing function.

Notes:
1. this will not work cross domains. parent document and the requested document must be in the same domain
2. this isn't technically AJAX because it doesn't use XML
View User's Profile View All Posts By User U2U Member
Khaled
Junior Member

Posts: 4
Registered: 3/19/2007
Location: Riyadh
Member Is Offline
posted on 3/20/2007 at 06:47 AM

Actually It use XML , So it is AJAX for sure :)

You understood that I want to submit date to server and wait for response ! >> It's not the case

Now I fixed that problem by changing :
httpRequest.open('POST', url, true); with httpRequest.open('GET', url, true);
GET instead of POST

Now it sends the request and wait for the response ;)

Thank u very much :)
View User's Profile View All Posts By User U2U Member
Post new thread

Related Links:

Go To Top


Powered by XMB 1.9.1 Nexus
Developed By Aventure Media & The XMB Group © 2002-2004