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


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

ajax request with no response

Started byAndrew Poulos <ap_prog@hotmail.com>
First post2012-12-09 10:43 +1100
Last post2012-12-10 00:53 +0100
Articles 9 — 4 participants

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


Contents

  ajax request with no response Andrew Poulos <ap_prog@hotmail.com> - 2012-12-09 10:43 +1100
    Re: ajax request with no response Stefan Weiss <krewecherl@gmail.com> - 2012-12-09 01:17 +0100
      Re: ajax request with no response JJ <jaejunks@glegooilma-swapit.com> - 2012-12-10 04:17 +0000
        Re: ajax request with no response Stefan Weiss <krewecherl@gmail.com> - 2012-12-10 11:03 +0100
          Re: ajax request with no response JJ <jaejunks@glegooilma-swapit.com> - 2012-12-11 11:06 +0000
    Re: ajax request with no response Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-09 19:51 +0100
      Re: ajax request with no response Andrew Poulos <ap_prog@hotmail.com> - 2012-12-10 08:17 +1100
        Re: ajax request with no response Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-10 00:25 +0100
        Re: ajax request with no response Stefan Weiss <krewecherl@gmail.com> - 2012-12-10 00:53 +0100

#17616 — ajax request with no response

FromAndrew Poulos <ap_prog@hotmail.com>
Date2012-12-09 10:43 +1100
Subjectajax request with no response
Message-ID<67WdnSfJBNQHTV7NnZ2dnUVZ_uGdnZ2d@westnet.com.au>
If I'm sending some info to a server using ajax and the "success" server 
action is to redirect to another page, do I need to worry about the 
(lack of a) response that the original page is expecting?

Andrew Poulos

[toc] | [next] | [standalone]


#17619

FromStefan Weiss <krewecherl@gmail.com>
Date2012-12-09 01:17 +0100
Message-ID<ka0lb7$32i$1@news.albasani.net>
In reply to#17616
On 2012-12-09 00:43, Andrew Poulos wrote:
> If I'm sending some info to a server using ajax and the "success" server 
> action is to redirect to another page, do I need to worry about the 
> (lack of a) response that the original page is expecting?

If it's an XHR request, there will be no navigation, and you will stay
on the original page. The server can redirect to another location, but
most XHR implementations just transparently follow the redirect and use
whatever the redirect target sends as responseText/responseXml. (There
may be some restrictions to that, especially if the redirect target is
not from the same origin. I have never tested that.)

If you do want to navigate away from the original page, don't let the
server do the redirect. Let the server return the new location to your
script (in whatever format you usually use to communicate with the
server), and the script then sets location.href.

- stefan

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


#17647

FromJJ <jaejunks@glegooilma-swapit.com>
Date2012-12-10 04:17 +0000
Message-ID<XnsA12573AE046F3jaejunksglegooilma@0.0.0.23>
In reply to#17619
Stefan Weiss <krewecherl@gmail.com> wrote:
> If it's an XHR request, there will be no navigation, and you will stay
> on the original page. The server can redirect to another location, but
> most XHR implementations just transparently follow the redirect and
> use whatever the redirect target sends as responseText/responseXml.
> (There may be some restrictions to that, especially if the redirect
> target is not from the same origin. I have never tested that.)
> 
> If you do want to navigate away from the original page, don't let the
> server do the redirect. Let the server return the new location to your
> script (in whatever format you usually use to communicate with the
> server), and the script then sets location.href.
> 
> - stefan

I thought there's a HTTP request header that can disallow server to 
respond a 3xx status codes, but I've searched through the HTTP specs and 
don't find any. Did I overlooked something?

I could only found that a server should not redirect a POST method 
requests.

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


#17650

FromStefan Weiss <krewecherl@gmail.com>
Date2012-12-10 11:03 +0100
Message-ID<ka4c0l$h9p$1@news.albasani.net>
In reply to#17647
On 2012-12-10 05:17, JJ wrote:
> I thought there's a HTTP request header that can disallow server to 
> respond a 3xx status codes, but I've searched through the HTTP specs and 
> don't find any. Did I overlooked something?

I don't think so, I've never heard of such a header.

> I could only found that a server should not redirect a POST method 
> requests.

Why not? Just use 303 See Other ("This method exists primarily to allow
the output of a POST-activated script to redirect the user agent to a
selected resource").

I use this all the time. A typical situation would be a web forum: a
user posts a message, and then periodically reloads the result page to
see if anybody has replied yet.

- stefan

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


#17673

FromJJ <jaejunks@glegooilma-swapit.com>
Date2012-12-11 11:06 +0000
Message-ID<XnsA126B8FEEC229jaejunksglegooilma@0.0.0.23>
In reply to#17650
Stefan Weiss <krewecherl@gmail.com> wrote:
>> I could only found that a server should not redirect a POST method 
>> requests.
> 
> Why not? Just use 303 See Other ("This method exists primarily to
> allow the output of a POST-activated script to redirect the user agent
> to a selected resource").
> 
> I use this all the time. A typical situation would be a web forum: a
> user posts a message, and then periodically reloads the result page to
> see if anybody has replied yet.
> 
> - stefan

My bad. I misunderstood the specs in RFC2616 "10.3 Redirection 3xx".

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


#17630

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-12-09 19:51 +0100
Message-ID<7171452.m6WORY6t7m@PointedEars.de>
In reply to#17616
Andrew Poulos wrote:

> If I'm sending some info to a server using ajax and the "success" server
> action is to redirect to another page, do I need to worry about the
> (lack of a) response that the original page is expecting?

There is always a response.  As much too often with your questions, why do 
you not try it *before* you post?

<http://www.catb.org/~esr/faqs/smart-questions.html#idp29963616>


PointedEars
-- 
var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
)  // Plone, register_function.js:16

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


#17631

FromAndrew Poulos <ap_prog@hotmail.com>
Date2012-12-10 08:17 +1100
Message-ID<0pudneAzZbF8YlnNnZ2dnUVZ_h-dnZ2d@westnet.com.au>
In reply to#17630
On 10/12/2012 5:51 AM, Thomas 'PointedEars' Lahn wrote:
> Andrew Poulos wrote:
>
>> If I'm sending some info to a server using ajax and the "success" server
>> action is to redirect to another page, do I need to worry about the
>> (lack of a) response that the original page is expecting?
>
> There is always a response.  As much too often with your questions, why do
> you not try it *before* you post?
>
> <http://www.catb.org/~esr/faqs/smart-questions.html#idp29963616>

1. You knew that "There is always a response." I did not. Nothing I've 
read about ajax stated that. Still I do not fully understand what "There 
is always a response." means.

2 You ask a valid question of me but I need some theoretical background 
otherwise I might fluke a solution that collapses when I try it in the 
"real" world.

Andrew Poulos

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


#17632

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-12-10 00:25 +0100
Message-ID<3615309.P3s4tL2RFq@PointedEars.de>
In reply to#17631
Andrew Poulos wrote:

> On 10/12/2012 5:51 AM, Thomas 'PointedEars' Lahn wrote:
>> Andrew Poulos wrote:
>>> If I'm sending some info to a server using ajax and the "success" server
>>> action is to redirect to another page, do I need to worry about the
>>> (lack of a) response that the original page is expecting?
>>
>> There is always a response.  As much too often with your questions, why
>> do you not try it *before* you post?
>>
>> <http://www.catb.org/~esr/faqs/smart-questions.html#idp29963616>
> 
> 1. You knew that "There is always a response." I did not. Nothing I've
> read about ajax stated that.

Simply trying it would have showed you.

> Still I do not fully understand what "There is always a response." means.

If there is a webserver on the other end, and behaves like you described, 
and if you use the term “redirect” correctly, it will send a(n) (HTTP) 
response.

> 2 You ask a valid question of me but I need some theoretical background
> otherwise I might fluke a solution that collapses when I try it in the
> "real" world.

First get rid of some misconceptions: ajax, page, original page.  Perhaps 
you also have a misconception about what a “redirect” is.  Then read:

<https://developer.mozilla.org/en/docs/AJAX> pp.
<http://en.wikipedia.org/wiki/HTTP> pp.

While you do it, be aware that those are wikis.


PointedEars
-- 
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
  -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)

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


#17633

FromStefan Weiss <krewecherl@gmail.com>
Date2012-12-10 00:53 +0100
Message-ID<ka3895$a7g$1@news.albasani.net>
In reply to#17631
On 2012-12-09 22:17, Andrew Poulos wrote:
> On 10/12/2012 5:51 AM, Thomas 'PointedEars' Lahn wrote:
>> There is always a response.  As much too often with your questions, why do
>> you not try it *before* you post?
>>
>> <http://www.catb.org/~esr/faqs/smart-questions.html#idp29963616>
> 
> 1. You knew that "There is always a response." I did not. Nothing I've 
> read about ajax stated that. Still I do not fully understand what "There 
> is always a response." means.

There isn't necessarily always a response from the XMLHttpRequest
target, but the XHR object will still (eventually) reach a readyState of 4.

This holds true even if

- the provided URL is not valid
- the URL could not be loaded (DNS failure, server down, ...)
- the connection breaks down before the response
- the remote server is shut down before it can send the response
- the remote server redirects to another URL
- the client calls the XHR's abort() method
- the client navigates away before receiving a response
- the XHR.timeout value was reached
- etc.

In theory, unless you set a timeout for the XHR (where supported), it
could take forever before you get to the readyState=4 stage, because TCP
connections don't have a maximum duration. In practice, I'd like to see
the system that can keep up a TCP connection forever. My personal record
was 2 months :)

- stefan

[toc] | [prev] | [standalone]


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


csiph-web