Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #23750 > unrolled thread

xhr call and changing page

Started byAndrew Poulos <ap_prog@hotmail.com>
First post2014-03-31 12:33 +1100
Last post2014-03-31 11:48 -0700
Articles 4 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  xhr call and changing page Andrew Poulos <ap_prog@hotmail.com> - 2014-03-31 12:33 +1100
    Re: xhr call and changing page Denis McMahon <denismfmcmahon@gmail.com> - 2014-03-31 02:35 +0000
    Re: xhr call and changing page Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-31 19:23 +0200
    Re: xhr call and changing page Danny <dann90038@gmail.com> - 2014-03-31 11:48 -0700

#23750 — xhr call and changing page

FromAndrew Poulos <ap_prog@hotmail.com>
Date2014-03-31 12:33 +1100
Subjectxhr call and changing page
Message-ID<YeKdnX0JJb6iW6XOnZ2dnUVZ_sidnZ2d@westnet.com.au>
When I send some data using AJAX to the server (to save to a db) and 
then immediately navigate to a new page what seems to be happening is 
that no data gets to the db.

Does changing the page that made the AJAX call cause the call to get 
cancelled?

I'm trying to track an elearning course. When the user closes the window 
containing the course I have a loop in the parent page that checks for 
the course's window. If the window cannot be found it updates the server 
with the "logout" time and then navigates to the course selection page.

Andrew Poulos

[toc] | [next] | [standalone]


#23751

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-03-31 02:35 +0000
Message-ID<lhak9q$8uu$1@dont-email.me>
In reply to#23750
On Mon, 31 Mar 2014 12:33:54 +1100, Andrew Poulos wrote:

> When I send some data using AJAX to the server (to save to a db) and
> then immediately navigate to a new page what seems to be happening is
> that no data gets to the db.
> 
> Does changing the page that made the AJAX call cause the call to get
> cancelled?
> 
> I'm trying to track an elearning course. When the user closes the window
> containing the course I have a loop in the parent page that checks for
> the course's window. If the window cannot be found it updates the server
> with the "logout" time and then navigates to the course selection page.

I suspect that any javascript on a web page executes in the context of 
the page that invokes it. Navigating away from that page probably 
terminates any executing code on the page. In the case of any outstanding 
ajax requests, I expect the browser would close the connections at the tcp 
level which were waiting for responses as the listener events would no 
longer be waiting at the javascript level.

If this drops the tcp connection, I have no idea what the server would 
receive, or how it would interpret it, but I can envisage that the server 
might see a closed connection as a request it should ignore (because it 
can't send a response).

I suspect therefore that this is going to be a server behaviour issue. 
What does the server do when the client drops the connection before the 
server has sent a response?

Do the server logs shed any light on what the server is seeing / doing? 
If not, can you increase the reporting level? If so, does that shed any 
light?

Perhaps the safest thing to do would wait until receiving a response from 
the server before changing page?

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#23754

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-03-31 19:23 +0200
Message-ID<4186496.FSMyk1E8Y6@PointedEars.de>
In reply to#23750
Andrew Poulos wrote:

> When I send some data using AJAX to the server (to save to a db) and
> then immediately navigate to a new page what seems to be happening is
> that no data gets to the db.
> 
> Does changing the page that made the AJAX call cause the call to get
> cancelled?

Obviously, as always (and please don't say “AJAX call”).  You need to avoid 
the race condition by not navigating before you are sure the request has 
been sent; even better, wait until the response has been received.
 
> I'm trying to track an elearning course. When the user closes the window
> containing the course I have a loop in the parent page that checks for
> the course's window.

A loop?

> If the window cannot be found it updates the server with the "logout" time
> and then navigates to the course selection page.

Also consider listening to events pertaining to navigating away/closing the 
window.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#23759

FromDanny <dann90038@gmail.com>
Date2014-03-31 11:48 -0700
Message-ID<101889bc-7191-4f94-97c8-00a134d24d3c@googlegroups.com>
In reply to#23750
To Andrew Poulos



as explained by Denis,   set your onreadystatechange handler
to wait for the readyState === 4, then do the new url load

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web