SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast bokz_42's Avatar
    Join Date
    Sep 2006
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple ajax script help

    so i have a this simple ajax code:

    function GetXmlHttpObject()
    {
    var xmlHttp=null;
    try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
    //Internet Explorer
    try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    }
    return xmlHttp;
    }

    function startbreak1(submitUser1breakStart){
    xmlHttp=GetXmlHttpObject();
    url = "postme.php?submitUser1breakStart="+submitUser1breakStart;
    xmlHttp.open("GET", url ,true);
    xmlHttp.onreadystatechange=
    function(){
    if (xmlHttp.readyState==4){
    response=xmlHttp.responseText;
    if (response.length>0){
    document.getElementById('span1stBreak').innerHTML = response;
    }else{
    document.getElementById('span1stBreak').innerHTML = "";
    }
    }else{
    document.getElementById('span1stBreak').innerHTML = "<strong>... loading</strong>";
    }
    };
    xmlHttp.send(null);
    }


    * my dilema is that when postme.php loads in the span from the main page, it does not interpret javascripts, all it does is interpret the php codes there. pls help im a newbie in using ajax and i would really appreciate the help. thanks a bunch!

    here is some scripts in postme.php

    <html>
    <head>
    <script>
    function sample() {
    //simple alert will do.
    alert("hi!!");
    }
    </script>
    <body>
    <?php
    echo "blah blah";
    ?>

    <script>
    sample();
    </script>
    </body>
    </head>
    </html>

  2. #2
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Scripts in Ajax Response will not work until you evaluate them. In third party libraries( like jQuery and Prototype), they will automatically evaluate JavaScript in Ajax response.


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
  •