Running server side code without submitting current page?

Discussion in 'Javascript' started by javelin, Nov 16, 2006.

  1. javelin

    javelin Guest

    I need to fire off some server side code, but I don't want to submit
    the page I'm on. I know that's not technically possible (without
    something like AJAX, maybe?). What I thought might work is to pop-up
    another window (invisibly?), have it run the code, close itself and
    return the results. What do you think, is it possible???

    Please let me know if you have any ideas.

    Thx!!!
     
    javelin, Nov 16, 2006
    #1
    1. Advertising

  2. javelin

    ASM Guest

    javelin a écrit :
    > I need to fire off some server side code, but I don't want to submit
    > the page I'm on. I know that's not technically possible (without
    > something like AJAX, maybe?). What I thought might work is to pop-up
    > another window (invisibly?), have it run the code, close itself and
    > return the results. What do you think, is it possible???
    >
    > Please let me know if you have any ideas.


    I've a lot :)

    You can play with a backward popup ( <body onload="opener.focus()">)
    You can also play with an invisible iframe.

    But more elegant is to use XMLHttpRequest (part of Ajax)

    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Nov 17, 2006
    #2
    1. Advertising

  3. javelin

    Randy Webb Guest

    ASM said the following on 11/16/2006 8:36 PM:
    > javelin a écrit :
    >> I need to fire off some server side code, but I don't want to submit
    >> the page I'm on. I know that's not technically possible (without
    >> something like AJAX, maybe?). What I thought might work is to pop-up
    >> another window (invisibly?), have it run the code, close itself and
    >> return the results. What do you think, is it possible???
    >>
    >> Please let me know if you have any ideas.

    >
    > I've a lot :)
    >
    > You can play with a backward popup ( <body onload="opener.focus()">)
    > You can also play with an invisible iframe.
    >
    > But more elegant is to use XMLHttpRequest (part of Ajax)


    No, the most elegant would be the one the FAQ refers to whereby you
    change the .src of an image and the server side script gets fired. Why
    make it harder than it has to be?

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Nov 17, 2006
    #3
  4. javelin

    javelin Guest

    Not sure I follow you. I don't know how to fire off the server side
    script. Can you point me to the FAQ or other refs?


    Randy Webb wrote:
    > ASM said the following on 11/16/2006 8:36 PM:
    > > javelin a écrit :
    > >> I need to fire off some server side code, but I don't want to submit
    > >> the page I'm on. I know that's not technically possible (without
    > >> something like AJAX, maybe?). What I thought might work is to pop-up
    > >> another window (invisibly?), have it run the code, close itself and
    > >> return the results. What do you think, is it possible???
    > >>
    > >> Please let me know if you have any ideas.

    > >
    > > I've a lot :)
    > >
    > > You can play with a backward popup ( <body onload="opener.focus()">)
    > > You can also play with an invisible iframe.
    > >
    > > But more elegant is to use XMLHttpRequest (part of Ajax)

    >
    > No, the most elegant would be the one the FAQ refers to whereby you
    > change the .src of an image and the server side script gets fired. Why
    > make it harder than it has to be?
    >
    > --
    > Randy
    > Chance Favors The Prepared Mind
    > comp.lang.javascript FAQ - http://jibbering.com/faq
    > Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    javelin, Nov 21, 2006
    #4
  5. javelin

    Jeremy Guest

    javelin wrote:
    > Randy Webb wrote:
    >> ASM said the following on 11/16/2006 8:36 PM:
    >>> But more elegant is to use XMLHttpRequest (part of Ajax)
    >>>

    >> No, the most elegant would be the one the FAQ refers to whereby you
    >> change the .src of an image and the server side script gets fired. Why
    >> make it harder than it has to be?

    >
    > Not sure I follow you. I don't know how to fire off the server side
    > script. Can you point me to the FAQ or other refs?
    >
    >


    We like to bottom-post in this group, to maintain the conversation
    ordering. I've fixed yours for you (see how I moved your text below
    Randy's?)

    What Randy means with the image source is that you can use some code
    like this:

    ------------
    var myScriptCall = new Image();
    myScriptCall.src = "/path/to/my/script";
    ------------

    Or, in DOM terms:

    ------------
    var myScriptCall = document.createElement("img");
    myScriptCall.src = "/path/to/my/script";

    //make it invisible but still load
    myScriptCall.style.width = "0px";
    document.body.appendChild(myScriptCall);
    -----------

    And your script will be requested (and therefore executed).

    However, since one of your requirements seems to be to "return the
    results", you are much better off with XMLHttpRequest - also known
    (often erroneously) as AJAX. It lets you create a javascript object
    which will go off and do a background request to your web server and
    return the result. Which is exactly what you want.

    Do some googling on XMLHttpRequest and see if you can get yourself
    started. It's not as hard as it looks. If you have trouble, come back
    and ask.

    Jeremy
     
    Jeremy, Nov 21, 2006
    #5
  6. javelin

    ASM Guest

    Jeremy a écrit :
    >
    > What Randy means with the image source is that you can use some code
    > like this:
    >
    > ------------
    > var myScriptCall = new Image();
    > myScriptCall.src = "/path/to/my/script";
    > ------------



    I've tried that

    myScriptCall.src = 'script.js'

    file script.js :

    alert('seen');


    Nothing happens ... no message box :-(

    (no error in FF console)



    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Nov 21, 2006
    #6
  7. javelin

    Randy Webb Guest

    ASM said the following on 11/21/2006 5:37 AM:
    > Jeremy a écrit :
    >>
    >> What Randy means with the image source is that you can use some code
    >> like this:
    >>
    >> ------------
    >> var myScriptCall = new Image();
    >> myScriptCall.src = "/path/to/my/script";
    >> ------------

    >
    >
    > I've tried that
    >
    > myScriptCall.src = 'script.js'
    >
    > file script.js :
    >
    > alert('seen');
    >
    >
    > Nothing happens ... no message box :-(


    The .src of an Image won't execute script. If you want to load script.js
    and have it executed, see this thread (or any other you can find
    searching for my name and "loadJSFile" in it).

    <URL:
    http://groups-beta.google.com/group/comp.lang.javascript/browse_thread/thread/145dcdbddbb78612/5fb5e75ca498ae6b?lnk=gst&q=Randy+Webb+LoadJSFile&rnum=4#5fb5e75ca498ae6b>

    <URL:
    http://groups-beta.google.com/group/comp.lang.javascript/browse_thread/thread/b1cee183e87aadc2/0b637acb0115f1f8?lnk=gst&q=Randy+Webb+LoadJSFile&rnum=2#0b637acb0115f1f8>

    The second one has a link to this page:
    <URL: http://members.aol.com/_ht_a/hikksnotathome/loadJSFile/index.html>

    Can you test that page for me if you have any browsers that aren't
    listed on that page? If you have a different OS but the same version
    browser I would appreciate that also as there may be an OS difference in
    the page.

    You should get an alert when the page loads, and then clicking on the
    three buttons at the top you may or may not get an alert (depending on
    whether that method worked or not). OS ver, browser name and version.

    Anybody else reading this that can check that page and test it in any
    browser/OS not listed and let me know it would be appreciated as well.

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Nov 21, 2006
    #7
  8. javelin

    ASM Guest

    Randy Webb a écrit :
    > ASM said the following on 11/21/2006 5:37 AM:
    >>> ------------
    >>> var myScriptCall = new Image();

    >> myScriptCall.src = 'script.js'
    >>
    >> file script.js :
    >> alert('seen');
    >>
    >> Nothing happens ... no message box :-(

    >
    > The .src of an Image won't execute script. If you want to load script.js
    > and have it executed, see this thread (or any other you can find
    > searching for my name and "loadJSFile" in it).
    >
    > <URL:
    > http://groups-beta.google.com/group/comp.lang.javascript/browse_thread/thread/145dcdbddbb78612/5fb5e75ca498ae6b?lnk=gst&q=Randy+Webb+LoadJSFile&rnum=4#5fb5e75ca498ae6b>


    That doesn't answer to my question (I know this way to do)
    I'ld like to do it in JS 1.1 (JS without DOM)

    > The second one has a link to this page:
    > <URL: http://members.aol.com/_ht_a/hikksnotathome/loadJSFile/index.html>


    I've saw several times this page.
    And ... ?
    What have I to do with it ?
    Only right button works : fireFox 2, Safari 1.3.2.
    No button works : iCab beta 3.0.0
    All work : Opera 9.0
    All browsers except NC4.5 show the first alert.
    Mac OS 10.3.9

    NC4.5 doesn't like id="myScriptTag"


    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Nov 21, 2006
    #8
  9. In comp.lang.javascript message
    <>, Mon, 20 Nov 2006
    19:06:37, javelin <> wrote:
    >Not sure I follow you. I don't know how to fire off the server side
    >script. Can you point me to the FAQ or other refs?


    >> ...


    >> --
    >> Randy
    >> Chance Favors The Prepared Mind
    >> comp.lang.javascript FAQ - http://jibbering.com/faq
    >> Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/



    You seem to be rather obtuse today.
    You should read what you quote; if it's worth showing again to others,
    it's worth showing to yourself first.

    When you have read the FAQ thoroughly, you will know more about what you
    need to do when presenting responses.

    --
    (c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
    <URL:http://www.jibbering.com/faq/> Old RC FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr J R Stockton, Nov 21, 2006
    #9
  10. javelin

    javelin Guest

    I apologize for my apparent ignorance, Dr J. I was assuming the FAQ
    mentioned was a reference to a posting here on this , as I've seen FAQ
    postings in other newsgroups.

    Dr J R Stockton wrote:
    > In comp.lang.javascript message
    > <>, Mon, 20 Nov 2006
    > 19:06:37, javelin <> wrote:
    > >Not sure I follow you. I don't know how to fire off the server side
    > >script. Can you point me to the FAQ or other refs?

    >
    > >> ...

    >
    > >> --
    > >> Randy
    > >> Chance Favors The Prepared Mind
    > >> comp.lang.javascript FAQ - http://jibbering.com/faq
    > >> Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

    >
    >
    > You seem to be rather obtuse today.
    > You should read what you quote; if it's worth showing again to others,
    > it's worth showing to yourself first.
    >
    > When you have read the FAQ thoroughly, you will know more about what you
    > need to do when presenting responses.
    >
    > --
    > (c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
    > <URL:http://www.jibbering.com/faq/> Old RC FAQ of news:comp.lang.javascript
    > <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    > <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    javelin, Nov 22, 2006
    #10
  11. javelin

    javelin Guest

    Thanks David. I have some rudimentary knowledge of AJAX, and have used
    XML to display data in web pages. I don't think it will kill me, I was
    just not sure if it was the best tool for checking database on the fly.
    I actually have to call a component, so I'll have to see if AJAX will
    do the trick.

    Thanks again.

    David Golightly wrote:
    > javelin wrote:
    > > I need to fire off some server side code, but I don't want to submit
    > > the page I'm on. I know that's not technically possible (without
    > > something like AJAX, maybe?). What I thought might work is to pop-up
    > > another window (invisibly?), have it run the code, close itself and
    > > return the results. What do you think, is it possible???
    > >
    > > Please let me know if you have any ideas.
    > >
    > > Thx!!!

    >
    > If all you want is to ping the server without doing anything with the
    > results, see this faq:
    >
    > http://www.jibbering.com/faq/#FAQ4_34
    >
    > Otherwise, that's what Ajax is for. By the way, in case you think you
    > need to "install" Ajax or something, it's not like Flash - any modern
    > browser (IE5+, Firefox, Safari etc.) supports the technology Ajax is
    > based on built-in. It won't kill you to learn how it works.
     
    javelin, Nov 22, 2006
    #11
  12. javelin

    javelin Guest

    Jeremy wrote:
    > javelin wrote:
    > > Randy Webb wrote:
    > >> ASM said the following on 11/16/2006 8:36 PM:
    > >>> But more elegant is to use XMLHttpRequest (part of Ajax)
    > >>>
    > >> No, the most elegant would be the one the FAQ refers to whereby you
    > >> change the .src of an image and the server side script gets fired. Why
    > >> make it harder than it has to be?

    > >
    > > Not sure I follow you. I don't know how to fire off the server side
    > > script. Can you point me to the FAQ or other refs?
    > >
    > >

    >
    > We like to bottom-post in this group, to maintain the conversation
    > ordering. I've fixed yours for you (see how I moved your text below
    > Randy's?)
    >
    > What Randy means with the image source is that you can use some code
    > like this:
    >
    > ------------
    > var myScriptCall = new Image();
    > myScriptCall.src = "/path/to/my/script";
    > ------------
    >
    > Or, in DOM terms:
    >
    > ------------
    > var myScriptCall = document.createElement("img");
    > myScriptCall.src = "/path/to/my/script";
    >
    > //make it invisible but still load
    > myScriptCall.style.width = "0px";
    > document.body.appendChild(myScriptCall);
    > -----------
    >
    > And your script will be requested (and therefore executed).
    >
    > However, since one of your requirements seems to be to "return the
    > results", you are much better off with XMLHttpRequest - also known
    > (often erroneously) as AJAX. It lets you create a javascript object
    > which will go off and do a background request to your web server and
    > return the result. Which is exactly what you want.
    >
    > Do some googling on XMLHttpRequest and see if you can get yourself
    > started. It's not as hard as it looks. If you have trouble, come back
    > and ask.
    >
    > Jeremy


    Jeremy, I just got to your post after replying to a few others, so I'm
    sorry I top posted my replies on those as well. Thanks for the notice.

    Also, thanks for the reference to XMLHttpRequest. I'll be sure to
    research and test it. I am hoping I can figure out how to call
    components with it as well.

    Thanks once again.

    Javelin
     
    javelin, Nov 22, 2006
    #12
  13. In comp.lang.javascript message
    <>, Wed, 22 Nov
    2006 05:36:23, javelin <> wrote:
    >I apologize for my apparent ignorance, Dr J. I was assuming the FAQ
    >mentioned was a reference to a posting here on this , as I've seen FAQ
    >postings in other newsgroups.


    Don't apologise for your manifest ignorance and/or stupidity. Instead,
    terminate its manifestation By reading and understanding firstly what
    you quote and secondly the FAQ itself. Then consider posting further
    articles.

    >Dr J R Stockton wrote:


    >> You seem to be rather obtuse today.
    >> You should read what you quote; if it's worth showing again to others,
    >> it's worth showing to yourself first.
    >>
    >> When you have read the FAQ thoroughly, you will know more about what you
    >> need to do when presenting responses.
    >>
    >> --
    >> (c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
    >> <URL:http://www.jibbering.com/faq/> Old RC FAQ of news:comp.lang.javascript
    >> <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    >> <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.




    --
    (c) John Stockton, Surrey, UK. REPLYyyww merlyn demon co uk Turnpike 6.05.
    Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
    Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
    No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
     
    Dr J R Stockton, Nov 22, 2006
    #13
  14. javelin

    Yanick Guest

    javelin a écrit :

    > I need to fire off some server side code, but I don't want to submit
    > the page I'm on. I know that's not technically possible (without
    > something like AJAX, maybe?). What I thought might work is to pop-up
    > another window (invisibly?), have it run the code, close itself and
    > return the results. What do you think, is it possible???
    >
    > Please let me know if you have any ideas.
    >
    > Thx!!!



    Consider using an internal frame (<iframe>), and look at this document
    :

    http://www.oreillynet.com/pub/a/javascript/2002/02/08/iframe.html

    You might find what you're looking for.
     
    Yanick, Nov 23, 2006
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page