How to call JavaScript codes with ajax?!

Discussion in 'JavaScript' started by redhits, Oct 31, 2008.

  1. #1
    It's seem ok to call HTML code ...

    with a function like


    function query(){
    var dlist=encodeURIComponent(document.getElementById('dlist').value);
    http_request = new XMLHttpRequest();
    http_request.onreadystatechange = alertContents;
    http_request.open('GET', 'modules/general.php?domains='+dlist, true);
    http_request.send(null);
    document.getElementById('submit').innerHTML="<img src=images/back.gif border=0 class=cool onclick='goback();'></a>";
    }



    function alertContents() {
    if(http_request.readyState == 4){document.getElementById('domains').innerHTML=http_request.responseText;}
    }



    But the problem appears when i try to load some javascript from that modules/general.php page...
     
    redhits, Oct 31, 2008 IP
  2. rene7705

    rene7705 Peon

    Messages:
    233
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Did you set
    header("Content-type: text/javascript");

    in the php that serves the javascript?
     
    rene7705, Nov 11, 2008 IP