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


Groups > comp.lang.javascript > #33567

Re: Getting text with AJAX

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.javascript
Subject Re: Getting text with AJAX
Date Sat, 01 Jul 2017 12:10:24 +0100
Organization A noiseless patient Spider
Lines 37
Message-ID <871sq09zvj.fsf@bsb.me.uk> (permalink)
References <31a6bc47-820d-4029-9ff1-c46617cf7e6f@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain
Injection-Info mx02.eternal-september.org; posting-host="041c066391ca2b8f1f9730c78c417d85"; logging-data="4675"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/g3Oa5zMvM2bm8Sro/JW5l50ddEfGJS6o="
Cancel-Lock sha1:b/s57IwJIs/aEPCh394vHP9HEH8= sha1:ZmEDeuNz+W49IKpCcQQ6h4f+k/8=
X-BSB-Auth 1.d3dbec290b0dcaa2675b.20170701121024BST.871sq09zvj.fsf@bsb.me.uk
Xref csiph.com comp.lang.javascript:33567

Show key headers only | View raw


bit-naughty@hotmail.com writes:

> ...OK, so assume there's some text on the screen, like a headline, or
> topic, say. When it's clicked, the actual text has to be got (from the
> server), and shown.
> What would the coding look like? 
> (assume the text itself is on a MySQL db on the server, with some kind
> of "id" to it, which will be fetched by a PHP script -
> ie. www.site.com/gettext.php?articleid=210).

One possible outline:

1. The document could associate the ID with the headline using a data-*
attribute:

  <h1 data-article-id=210>Usenet not dead despite rumours</h1>

2. An click event handler is then associated with every headline.  I
usually do this on load:

  window.addEventListener('load', function () {
      var headlines = document.querySelectorAll('h1[data-article-id]');
      for (var i = 0; i < headlines.length; i++)
          headlines[i].addEventListener('click', ...);
  }, false);

3. That event handler constructs the required URL either by extracting
the ID from the event object (say via the target attribute).

4. It then creates an XMLHTTPRequest for that resource whose 'load'
handler will do whatever you want with the result.

It's all a bit vague because there are so many ways to handle the
details and very little in your question to guide an answer.

-- 
Ben.

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


Thread

Getting text with AJAX bit-naughty@hotmail.com - 2017-07-01 02:49 -0700
  Re: Getting text with AJAX Luuk <luuk@invalid.lan> - 2017-07-01 11:56 +0200
  Re: Getting text with AJAX Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-07-01 12:10 +0100
  Re: Getting text with AJAX JJ <jj4public@vfemail.net> - 2017-07-01 21:35 +0700
  Re: Getting text with AJAX JR <jrfaqcom@gmail.com> - 2017-07-02 13:37 -0300

csiph-web