Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #15759
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: XHR: Passing Parameters to a ready-state-change Function |
| Date | 2012-09-07 09:15 +0100 |
| Organization | Personal Software |
| Message-ID | <timstreater-90133A.09150507092012@news.individual.net> (permalink) |
| References | <09ef48tfsgucbl7m49ggao3be5r0kb7v13@4ax.com> <k2akj4$bca$1@news.albasani.net> <hs9i48l1r77mh36nj9jq6jofp9h837o0pu@4ax.com> |
In article <hs9i48l1r77mh36nj9jq6jofp9h837o0pu@4ax.com>,
Gene Wirchenko <genew@ocis.net> wrote:
> On Thu, 06 Sep 2012 18:56:04 +0200, Stefan Weiss
> <krewecherl@gmail.com> wrote:
>
> [snip]
>
> > function fetch (url, callback) {
> > // (minimal example)
> > var xhr = new XMLHttpRequest();
> > xhr.open("GET", url, true);
> > xhr.onreadystatechange = function () {
> > if (xhr.readyState == "4") {
> > callback(xhr.responseText);
> > }
> > };
> > xhr.send();
> > }
> >
> >- then this is how you can direct the result to one of the two handlers:
> >
> > fetch("/a.txt", dataHandler1);
> > fetch("/a.txt", dataHandler2);
> >
> >What am I missing?
>
> Once again, it is me missing things.
>
> OK, I have worked with this some more.
>
> I need to handle errors.
What sort of errors are you referring to? Do you mean xhr failures or do
you mean errors you have detected and are reporting back vis the ajax
mechanism?
> If I understand correctly, I am forced
> to do that in the state change function or something called by it. So
> what you call callback will have to have this handling.
Of course. That's where the processing of the responseText takes place.
By the way, as has been pointed out you need to check that status==200
also. You also need to set xhr = null when you've finished with it.
--
Tim
"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
XHR: Passing Parameters to a ready-state-change Function Gene Wirchenko <genew@ocis.net> - 2012-09-05 13:53 -0700
Re: XHR: Passing Parameters to a ready-state-change Function Jim T. <x@y.z> - 2012-09-05 17:46 -0400
Re: XHR: Passing Parameters to a ready-state-change Function Gene Wirchenko <genew@ocis.net> - 2012-09-05 17:30 -0700
Re: XHR: Passing Parameters to a ready-state-change Function Jim T. <x@y.z> - 2012-09-05 20:55 -0400
Re: XHR: Passing Parameters to a ready-state-change Function Jim T. <x@y.z> - 2012-09-05 21:43 -0400
Re: XHR: Passing Parameters to a ready-state-change Function Jim T. <x@y.z> - 2012-09-05 21:49 -0400
Re: XHR: Passing Parameters to a ready-state-change Function Stefan Weiss <krewecherl@gmail.com> - 2012-09-06 18:56 +0200
Re: XHR: Passing Parameters to a ready-state-change Function Gene Wirchenko <genew@ocis.net> - 2012-09-06 10:55 -0700
Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-06 21:38 +0200
Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-06 21:49 +0200
Re: XHR: Passing Parameters to a ready-state-change Function Gene Wirchenko <genew@ocis.net> - 2012-09-06 15:49 -0700
Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-07 09:15 +0100
Re: XHR: Passing Parameters to a ready-state-change Function Gene Wirchenko <genew@ocis.net> - 2012-09-07 09:58 -0700
Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-07 19:14 +0100
Re: XHR: Passing Parameters to a ready-state-change Function cezary.tomczyk@gmail.com - 2012-09-07 13:51 -0700
Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-08 00:52 +0200
Re: XHR: Passing Parameters to a ready-state-change Function cezary.tomczyk@gmail.com - 2012-09-07 16:32 -0700
Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-08 09:48 +0200
Re: XHR: Passing Parameters to a ready-state-change Function Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-09-08 02:09 -0700
Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-08 11:09 +0100
Re: XHR: Passing Parameters to a ready-state-change Function Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-09-08 03:39 -0700
Re: XHR: Passing Parameters to a ready-state-change Function John G Harris <john@nospam.demon.co.uk> - 2012-09-08 15:00 +0100
Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-07 23:44 +0200
Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-07 23:08 +0100
Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-08 00:46 +0200
Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-08 11:11 +0100
Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-08 14:21 +0200
Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-08 17:06 +0100
Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-08 20:41 +0200
Re: XHR: Passing Parameters to a ready-state-change Function Dr J R Stockton <reply1236@merlyn.demon.co.uk.invalid> - 2012-09-09 20:04 +0100
Re: XHR: Passing Parameters to a ready-state-change Function Gene Wirchenko <genew@ocis.net> - 2012-09-09 18:40 -0700
Re: XHR: Passing Parameters to a ready-state-change Function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-09-10 07:21 +0000
Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-10 09:03 +0100
Re: XHR: Passing Parameters to a ready-state-change Function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-09-10 13:59 +0000
Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-10 15:35 +0100
Re: XHR: Passing Parameters to a ready-state-change Function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-09-10 22:42 +0000
Re: XHR: Passing Parameters to a ready-state-change Function Scott Sauyet <scott.sauyet@gmail.com> - 2012-09-11 10:09 -0700
Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-11 22:42 +0100
csiph-web