Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-12-2009, 11:31 AM   PM User | #1
jayapalchandran
New Coder

 
Join Date: Jan 2007
Location: Chennai, Tamil Nadu, India
Posts: 69
Thanks: 4
Thanked 0 Times in 0 Posts
jayapalchandran is an unknown quantity at this point
ajax synchronous request, page refresh and the error

Hi,
I have been using asynchronous requests for a long time. so the response was processed in a callback function. I thought of not using async so i made synchronous requests. The reason is that i dont have to have two more lines for checking the status and the onreadystatechange....

my synchronous requests would be like this...

Code:
var jax = createAjax(); // this function returns the XMLHTTPRequest object
jax.open('POST',url,false); //here false is to do sync request.
jax.setRequestHeader('Content-Type: application/x-www-form-urlencoded');
jax.send(parameters);
// once the above line is executed the process waits for the response and when it gets the response form the server then the next line is executed.
alert(jax.responseText); // here i process the response text.
so from the code you can understand that there is no need of a callback function and if conditions to check ready state... ...

So there is no problem in the above code. The problem araises here...

if i press the F5 (refresh) key or do a page refresh when the process is waiting for the response i get an (NS ERROR firefox ( i have not yet checked that in IE browsers) (javascript error) though the process completes successfully. why?

Do we have to check whether the page is navigating away while in synchronous operation and abort the request?

or what could be the reason for the error. This will not happen in async requests because that is also the reason for async...

so i give a sync request and before the response is received if i navigate away or reload the page i get the error.

???
__________________
http://vikku.info/
- யானைக்கும் அடிசறுக்கும்

Last edited by jayapalchandran; 12-12-2009 at 11:34 AM..
jayapalchandran is offline   Reply With Quote
Old 12-12-2009, 01:46 PM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by jayapalchandran View Post
Hi,
I have been using asynchronous requests for a long time. so the response was processed in a callback function. I thought of not using async so i made synchronous requests. The reason is that i dont have to have two more lines for checking the status and the onreadystatechange....

my synchronous requests would be like this...

Code:
var jax = createAjax(); // this function returns the XMLHTTPRequest object
jax.open('POST',url,false); //here false is to do sync request.
jax.setRequestHeader('Content-Type: application/x-www-form-urlencoded');
jax.send(parameters);
// once the above line is executed the process waits for the response and when it gets the response form the server then the next line is executed.
alert(jax.responseText); // here i process the response text.
so from the code you can understand that there is no need of a callback function and if conditions to check ready state... ...

So there is no problem in the above code. The problem araises here...

if i press the F5 (refresh) key or do a page refresh when the process is waiting for the response i get an (NS ERROR firefox ( i have not yet checked that in IE browsers) (javascript error) though the process completes successfully. why?
because server response is cached? check with firebug if my assumption is correct.

Quote:
Do we have to check whether the page is navigating away while in synchronous operation and abort the request?

or what could be the reason for the error. This will not happen in async requests because that is also the reason for async...

so i give a sync request and before the response is received if i navigate away or reload the page i get the error.

???
post full NS_ERROR line, please.

best regards
oesxyl is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:09 AM.


Advertisement
Log in to turn off these ads.