SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to enable javascript in an ajax layer loaded file???

    How do i enable .js in an ajax layer loaded file? Alle i see is the html but the .js doesn't seem to work and causes errors??

    Any tips?

  2. #2
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.
    Try a think like this:

    PHP Code:
    I've tried it with xhr.responseText= '<p>Hello</p><script language=\"javascript\">alert('Hello')</script>'
    var t =xhr.responseText;
    t = execJS(t);
    $("
    div1").innerHTML = t;
    function execJS(t)
    {
        var p1 = 0, p2 = 0, p3 = 0, p4 = 0;
        p1 = t.indexOf("
    <" + "script", 0);
        if(p1 == -1) return t;
        
        p2 = t.indexOf("
    >", p1 + 7) + 1;
        p3 = t.indexOf("
    <" + "/script>", p2);
        p4 = p3 + 9;
        
        var c = t.substring(p2, p3);
        var s = document.createElement("
    script");
        s.type = "
    text/javascript";
        s.text = c;
        document.getElementsByTagName("
    head")[0].appendChild(s);
        
        t = t.substring(0, p1) + t.substr(p4);
        return t;


    Bye.

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please post your code to say what you mean by the "Layer Loaded"... often the easiest technique is to have your server return some data - in JSON ... and then just put the data back into the DOM where you need it. Javascript will never stop working in your page if you use this approach.

    Returning a whole HTML page or even HTML fragments is often much more difficult and fraught with errors.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •