Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Why javascript loaded in ajax not working ?

    Why javascript loaded in ajax not working ?

    I load a javascript file using ajax - but found to not work.
    This js file must be used only for that page.

  • #2
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    Post some come please to check the problem.

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You can not set javascript with innerHTML. It will not be evaluated. If you want to do it, you need to evaluate it yourself. If you use a library such as Prototype.js or JQuery, they have it built in. If you are just fetching a JavaScript file, there is no need to use Ajax, you just need createElement and appendChild.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #4
    New Coder
    Join Date
    Jun 2009
    Posts
    35
    Thanks
    0
    Thanked 2 Times in 2 Posts
    use these code to upend the javascript file.

    var head = document.getElementsByTagName('head').item(0);
    var url ="filepath";

    try
    {

    var s = document.createElement('script');
    url = url + '?random=' + sRn;

    s.src = url;
    s.type = 'text/javascript';
    s.defer = true;
    s.id = 'visitorConsole';
    void(head.appendChild(s));


    }
    catch(e){

    }
    Live chat software - chat with your web site visitors in real time.
    Internet web directory - list of top100 sites in diffrent category

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    if you are loading a .js file, simply call eval(obj.responseText), where obj is the AJAX object...

    if you are loading html, you'll have to find the script tag text using RegExp, and then call eval() separately on each one in order.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%


  •  

    Tags for this Thread

    Posting Permissions

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