Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #15747
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: XHR: Passing Parameters to a ready-state-change Function |
| Date | 2012-09-06 18:56 +0200 |
| Organization | albasani.net |
| Message-ID | <k2akj4$bca$1@news.albasani.net> (permalink) |
| References | <09ef48tfsgucbl7m49ggao3be5r0kb7v13@4ax.com> |
On 2012-09-05 22:53, Gene Wirchenko wrote:
> Is there any way to pass parameters to the ready-state-change
> function that checks the progress of a request? I am currently using
> a global. I would prefer not to.
>
> What I want to pass is the name of a data-handling function to be
> executed if there is data returned.
(I hope you don't actually want to pass the _name_ of the callback
function, but rather a reference to the function.)
I'm afraid I don't understand what the actual problem is. If you have
two data handler functions -
function dataHandler1 (str) {
alert("data handler 1 received: " + str);
}
function dataHandler2 (str) {
alert("data handler 2 received: " + str);
}
- and some generic function to do the XHR stuff -
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?
- stefan
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