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


Groups > comp.lang.javascript > #28638

Re: Can AJAX request a .js file?

From Stefan Weiss <krewecherl@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Can AJAX request a .js file?
Date 2015-09-05 03:12 +0200
Organization albasani.net
Message-ID <msdfib$7n5$1@news.albasani.net> (permalink)
References (4 earlier) <92e68ba6-df1f-4479-921d-15bb219aba89@googlegroups.com> <msaig8$4b8$1@solani.org> <f5208286-843f-49b5-be3f-522c0f3789ab@googlegroups.com> <5hhjualgri65bc4omhpri9mo59560f56er@4ax.com> <525a746a-5a75-4872-91e5-9784b02eb7e7@googlegroups.com>

Show all headers | View raw


On 2015-09-05 00:47, Jay Braun wrote:
>     setInterval(
>        function() {
>           var fileref;
>           if (fileref===undefined) {
>              console.log("creating script");
>              fileref=document.createElementNS (xmlns, "script");
>              fileref.setAttribute("type","text/javascript");
>              fileref.setAttribute("src", "var.js");
>              console.log("calling repaint");
>              repaint(xmlns, svgElem);
>              fileref.remove();
>              fileref=undefined;
>           }
>        }, 3000 );
> 
> Note that the messages logged to the browser console are being output
> every 3 seconds. Each call to repaint executes the logic of the first
> version of the script, even though it has been overwritten.

You never add `fileref` to the document, so nothing gets overwritten.
Try something along the lines of

    document.body.appendChild(fileref);

before you call `repaint()`.

If I understand correctly, the C program on the server side creates JS
code to alter the SVG contents, which then gets evaluated on the client,
replacing an existing function. That's one way to do it, but not
necessarily the most efficient or elegant one. I haven't read all of the
thread up to this point, so this may have been suggested before... if I
were to design this, it would probably look like this:

  1. client polls the server for new data, using XMLHttpRequest
  2. server collects data and sends a JSON response
  3. client receives JSON and creates a JS object or array from it
  4. client calls `repaint(newData)`
  [repeat]

Obviously, this would require modifying the server-side program; I don't
know if that's an option for you.


- stefan

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


Thread

Can AJAX request a .js file? Jay Braun <lyngwyst@gmail.com> - 2015-09-02 14:47 -0700
  Re: Can AJAX request a .js file? "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-09-03 00:11 +0200
    Re: Can AJAX request a .js file? Jay Braun <lyngwyst@gmail.com> - 2015-09-02 15:15 -0700
      Re: Can AJAX request a .js file? "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-09-03 00:46 +0200
        Re: Can AJAX request a .js file? Jay Braun <lyngwyst@gmail.com> - 2015-09-03 12:50 -0700
          Re: Can AJAX request a .js file? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-04 00:14 +0200
          Re: Can AJAX request a .js file? "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-09-04 00:44 +0200
            Re: Can AJAX request a .js file? Jay Braun <lyngwyst@gmail.com> - 2015-09-03 18:52 -0700
              Re: Can AJAX request a .js file? Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2015-09-04 18:28 +0200
                Re: Can AJAX request a .js file? Jay Braun <lyngwyst@gmail.com> - 2015-09-04 15:47 -0700
                Re: Can AJAX request a .js file? Stefan Weiss <krewecherl@gmail.com> - 2015-09-05 03:12 +0200
                Re: Can AJAX request a .js file? Jay Braun <lyngwyst@gmail.com> - 2015-09-05 20:09 -0700

csiph-web