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


Groups > comp.lang.javascript > #15747

Re: XHR: Passing Parameters to a ready-state-change Function

Path csiph.com!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail
From Stefan Weiss <krewecherl@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: XHR: Passing Parameters to a ready-state-change Function
Date Thu, 06 Sep 2012 18:56:04 +0200
Organization albasani.net
Lines 45
Message-ID <k2akj4$bca$1@news.albasani.net> (permalink)
References <09ef48tfsgucbl7m49ggao3be5r0kb7v13@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace news.albasani.net pwD0vuq8QyzOtKnX4vVHOUq5/Bwg0Z9dkPOFzk32RGI/TJbcPb8mFwKwapq3pwnJkUxjSeDZXkiNQw5J2jt+u6mFvk+kd7IUxO+u1asiDMybfb1POW42Zy4Rikjkfb5G
NNTP-Posting-Date Thu, 6 Sep 2012 16:56:04 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="4pkxoPyQcz5C2I8GGXa0De93t8AlrrCkox8iHMZehW7kei0kiCWdtstrb0mPtpC5Kau87fuasuK+cY7ODUe/HiivFsH0g85EtJ1lieSUAnyeLA4gZDCEj1rseqbcbBc2"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0
In-Reply-To <09ef48tfsgucbl7m49ggao3be5r0kb7v13@4ax.com>
Cancel-Lock sha1:t2fVIABneUxq+lTZB5agUOt1F6k=
Xref csiph.com comp.lang.javascript:15747

Show key headers only | View raw


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


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