How to add <script /> refs in ajax call

Posted on 2009-04-19
Last Modified: 2012-06-27
I'm noticing that when i look at my html code from fire fox that if i make ajax call my <script tags /> are removed. Is this standard precedure. How do you then do client side validation.

ie Page1 makes an ajax call and gets the content of Page2 which contains a form.

I'm noticing that Page2 is having its <script /> tags remove. Kill my validation.
Question by:frosty1
    LVL 39

    Expert Comment

    No, script tags are not removed by firefox. Your code or transformation might be doing that. It is a fact, however, that the code inside script tags is generally not executed (and having script code in an ajax response is generally considered a bad practice, but that's a different story).

    There are several libraries that can help you with this issue. One is Prototype.js, which has methods to execute the returned javascript automatically, and another is jquery, which, iirc, has about the same possibilities.

    -- Abel --

    Author Comment

    thanks, that good info.

    Actually i'm using prototype

    Here is my function. When form.aspx is render it is minus the <script  /> tags. I need this to validate the form on form.aspx

    function openOverlay (lat, lng, zoom) {
          new Effect.Appear('curtain', { from: 0.0, to: 0.70, duration: 0.20 });
          new Effect.Appear('display', { from: 0.0, to: 1.0, duration: 0.20, afterFinish: function () {

          new Ajax.Updater('display', '/maps/map1/flagform.aspx?lat=' + lat + '&lng=' + lng + '&zoom=' + zoom, { method: 'get' });
          } });
    LVL 39

    Accepted Solution

    From the manpages of prototype, use the evalScripts = true parameter. An example I found here: where you can also find some extra notes on the subject.

       var myAjax = new Ajax.Updater(
                        method: 'get',
                        parameters: pars,
                        evalScripts: true,
                        onFailure: reportError

    Open in new window


    Author Comment

    wow , great response.

    So as abel saids, you need to part thru evalscript = true.

    also, include the script tags in the parent, in my case the validation.js needed to be in the page that called form.

    LVL 39

    Expert Comment

    > wow , great response.

    thx for the compliment. I remember that I was stumbling upon the same issue, about five years ago, and it took me ages to fix it. Then came prototype and the likes of them, making life much easier.

    tx for the points,
    -- Abel --

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
    Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
    Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
    The viewer will learn how to count occurrences of each item in an array.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now