Eval Script Tags in Ajax Response

I found this code after many research, and back

function parse_script(str)
{
var scripts = (str.match(/]*)>([sS]*?)</script>/g));
if (scripts && scripts.length)
{
for(var i=0;i
{
var arr = scripts[i].match(/]*)>([sS]*?)</script>/im);
var s;
if (YAHOO.env.ua.ie > 0)
{
s = document.createElement('SCRIPT');
s.text = arr[2];
}
else
{
s = document.createElement('script');
s.appendChild( document.createTextNode( arr[2] ));
}

document.getElementsByTagName(“head”)[0].appendChild(s);
}
}
}

4 Responses to “Eval Script Tags in Ajax Response”

  1. Harvey Says:

    thx alot for the fast answer, since i use jquery all the time, but my javascript code is not fireing from the loaded content?

     $.ajax(
      {
        type: 'GET',
        url: url+'?randval='+Math.random(),
        dataType: "html",
        success: function (j)
          {
            //fill content
            document.getElementById('page_content').innerHTML = (j);
          },
          error: function (data)
            {
              //something went wrong
             aaleerrttt(unescape("something went wrong"));
            }
        });
    }
    
  2. Harvey Says:

    var scripts = (str.match(/]*)>([sS]*?)/g));

    on this line ie has en error “missing /” and firebug tells me: “invalid regular expression flag s”

    how can i fix this error?


Share your thoughts & feedback

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: