• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

How to add <script /> refs in ajax call

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.
0
frosty1
Asked:
frosty1
  • 3
  • 2
1 Solution
 
abelCommented:
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 --
0
 
frosty1Author Commented:
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) {
      
      map.closeInfoWindow();
      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' });
      } });
}
0
 
abelCommented:
From the manpages of prototype, use the evalScripts = true parameter. An example I found here: http://www.salix.gr/prototype_ajax_what_learned where you can also find some extra notes on the subject.



   var myAjax = new Ajax.Updater(
                    'container',
                    url,
                    {
                    asynchronous:true,
                    method: 'get',
                    parameters: pars,
                    evalScripts: true,
                    onFailure: reportError
                    }
                 );

Open in new window

0
 
frosty1Author Commented:
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.

0
 
abelCommented:
> 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 --
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now