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


Groups > comp.lang.javascript > #20550

Re: Ajax issue

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <1650600.4TcKdCVReu@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Organization PointedEars Software (PES)
Date Fri, 05 Jul 2013 11:38:27 +0200
User-Agent KNode/4.10.4
Content-Transfer-Encoding 8Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: Ajax issue
Newsgroups comp.lang.javascript
References <492ccf76-c92f-4b97-85d9-1f1f926bedee@googlegroups.com> <f67e3cc5-5fad-4650-86ab-e7b6e9770b9e@googlegroups.com> <1372953269.FrdeS7i7de@PointedEars.de> <3c881e35-a08f-44b9-b514-510ba4023f91@googlegroups.com>
MIME-Version 1.0
Lines 134
NNTP-Posting-Date 05 Jul 2013 11:40:56 CEST
NNTP-Posting-Host f8744b4f.newsspool4.arcor-online.net
X-Trace DXC=j9EJnL^TZM>;]cDoEWD6A44IUK<Cl32<14Fo<]lROoR18kF<OcfhCO;C?h^emQ26N;DZm8W4\YJN<b@mF9jNikd57a5\<`>]gf>WHZ=D34RII1
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:20550

Show key headers only | View raw


Bart Van der Donck <bart@nijlen.com> wrote:
                    ^^^^^^^^^^^^^^^
Still not fixed.  Well, you have probably nothing important to say anyway, 
let alone something correct.

> Thomas 'PointedEars' Lahn wrote:
>> Bart Van der Donck <bart@nijlen.com> wrote:
>>> 1. You're talking about calling [cit.] "the second
>>> web service in the success function of the first
>>> one". This is not recommended;
>> 
>> Wrong.
>>
>>> it is better to cleanly finish the first AJAX-
>>> function before proceeding;
>> 
>> That has happened when the “success function of
>> the first one” is called.
> 
> I read it different, especially because of the word "in". Calling [cit.]
> "the second web service *in* the success function of the first one" sounds
> at least suspicious; maybe the XHR-object is still in use, maybe the
> buffer is not empty yet, etc. In short: first properly finish the first,
> and then go to the second.

What is meant here is with “call the second web service in the *success* 
function of the first one” can only be, in essence, either

  var xhr = new XMLHttpRequest();
  xhr.open("GET", "http://first.web.service.example", true);
  xhr.onreadystatechange = function () {
    if (xhr.readyState == 4 && xhr.status == 200)
    {
      xhr.open("GET", "http://second.web.service.example", true);
      xhr.onreadystatechange = function () {
        // …
      };
      xhr.send(null);
    }
  };
  xhr.send(null);

or (W3C XMLHttpRequest API [1]):

  var xhr = new XMLHttpRequest();
  xhr.open("GET", "http://first.web.service.example", true);
  xhr.onload = function () {
    xhr.open("GET", "http://second.web.service.example", true);
    xhr.onload = function () {
      // …
    };
    xhr.send(null);
  };
  xhr.send(null);

And there is no harm in that approach.  In fact, it is wise to reuse the 
“xhr” variable and referred object value when possible¹.

That is, assuming the request-response handling is all done *asynchronously* 
as it should be, which I doubt here.  See below.

_______
¹  That is a *timing* issue: with .readyState == 4, or .onload, the previous
   request-response processing is, literally, “DONE”, and the object is
   available for reuse.

[1] <http://www.w3.org/TR/2012/WD-XMLHttpRequest-20121206/>
 
>>> 2. A 'setTimeout()'-function *might* *maybe* help;
>> 
>> Wrong.  A setTimeout() call will increase the risk
>> of a timing problem as you can never know how long
>> it takes to receive and process the first response.
> 
> But the response time has nothing to do with it.

Yes, it has.

> It's only about giving a bit of time to the buffer (esp. in MSIE) in order
> to end the current job/s and to continue in a clean way. It's not
> guaranteed at all that this will help here; see *might* and *maybe*. But I
> do remember cases were it was useful (MSIE, not XHR related).

You want to sound authoritative, but in fact you have no clue what you are 
talking about.  “… [give] … time to the buffer … to end the current job 
[…]”?  OMG, RTFM.

>>> 3. Common 'XMLHttpRequest'-techniques typically
>>> use some variables. You would want to make sure
>>> that none of those are repeated in the second
>>> function,
>> 
>> Wrong.  Instead, it is wise to reuse variables
>> that are no longer used.
> 
> Absolutely not! You only open the door to all kinds of misunderstandings,
> bugs and unnecessary complexity. […]

IBTD.

> >> and that their scoping is correct;
> > 
> > Correct.  A common mistake is to use the same XHR
> > object twice, while the response handling for the
> > first request with that object is still in 
> > progress.  XHR libraries like JSX:http.js implement
> > approaches that prevent that from happening.
> 
> That could very well be the OP's problem indeed.

Unlikely.  It is much more likely that the “the HTML UI freezes” is caused 
by synchronous response-request-handling (“false”) that should have been 
asynchronous (“true”) as that is the main common cause for this condition 
due to the single-threaded nature of many ECMAScript implementations in Web 
browsers.

>>> 4. Not to say that AJAX is bad, but similar
>>> techniques exist which form IMHO certainly a good
>>> alternative, such as iframes or server-side logic.
>> 
>> Utter nonsense.
> 
> I'm more interested in an Argumentarium rather than a meaningless
> oneliner.

Present *your* arguments supporting *your* statements *first*.  Just saying 
something is good, or better than, or bad, or worse than, something else,
does not make it so.

-- 
PointedEars

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

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Ajax issue saurabh.khemka4@gmail.com - 2013-06-29 07:59 -0700
  Re: Ajax issue JJ <duh@nah.meh> - 2013-06-29 22:07 +0700
  Re: Ajax issue Bart Van der Donck <bart@nijlen.com> - 2013-07-04 00:33 -0700
    Re: Ajax issue Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-07-04 16:26 +0200
      Re: Ajax issue Bart Van der Donck <bart@nijlen.com> - 2013-07-05 01:15 -0700
        Re: Ajax issue Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-07-05 11:38 +0200
          Re: Ajax issue Bart Van der Donck <bart@nijlen.com> - 2013-07-05 07:48 -0700
            Re: Ajax issue Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-07-05 20:18 +0200
      Re: Ajax issue John Harris <niam@jghnorth.org.uk.invalid> - 2013-07-05 15:28 +0100
  Re: Ajax issue Matt Tacchi <mangamatt81@gmail.com> - 2013-07-11 00:34 -0700
    Re: Ajax issue Tim Streater <timstreater@greenbee.net> - 2013-07-11 09:34 +0100

csiph-web