www.webdeveloper.com
Results 1 to 4 of 4

Thread: How to call back this basic http request?

  1. #1
    Join Date
    Apr 2007
    Posts
    209

    How to call back this basic http request?

    Here's a working http request that is set up correctly. If you upload it named as anything.html along with a page named test.php, it will call whatever text you put in test.php It will put the text in the div id named T1. It does already.

    Quote:
    <html>
    <head>
    <script type="text/javascript">
    function myNewXMLobject(){
    var xmlhttp=false;
    try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
    xmlhttp = false;
    }
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    try {
    xmlhttp = new XMLHttpRequest();
    } catch (e) {
    xmlhttp=false;
    }
    }
    if (!xmlhttp && window.createRequest) {
    try {
    xmlhttp = window.createRequest();
    } catch (e) {
    xmlhttp=false;
    }
    }
    return xmlhttp;
    }
    xmlobject=myNewXMLobject();
    function up()
    {xmlobject.open("GET", "test.php",true);
    xmlobject.onreadystatechange=function() {
    if (xmlobject.readyState==4) {
    document.getElementById('T1').innerHTML=xmlobject.responseText;
    alert(xmlobject.responseText)
    }
    }
    xmlobject.send(null)
    }
    </script>
    </head>
    <body onload="up();">
    <div id="T1" style="border:1px solid black;height:100;width:150"></div>
    </body>
    </html>

    I need help keeping the request going. So that after it pulls test.php it will repull it again from scratch after so much time. I tried setInterval(' ',10000); but I didn't know where to set it and which function to use for it. I also didn't know if the body onload was keeping it from recalling test.php all over again. I really need some help on finishing this what I am trying isn't working, thank you.

  2. #2
    Join Date
    Apr 2007
    Posts
    209
    Doesn't anyone know how to keep http requests going? Thanks.

  3. #3
    Join Date
    Apr 2007
    Posts
    209
    Ok I got the timer working but have one last question following.

    In the test.php page is this.
    PHP Code:
    <?php 
    if ($_GET['act'] == "countPosts") { 
    $getfile date("s");
    $imagefile "file" $getfile ".jpg";
    echo 
    "<img src='/$imagefile'>";
    ?>
    How do I get this javascript function
    Code:
    function handleResponse() { 
         
            if(http.readyState == 4 && http.status == 200){ 
         
                // Text returned FROM PHP script 
                var response = http.responseText; 
         
                if(response) { 
                    // UPDATE ajaxTest content 
                    document.getElementById("countPosts").innerHTML = response; 
                    setTimeout('countPosts()',2000); 
                }
    To show an image as well as text? Right now its pulling the correct image from the php but its not showing it as an image.

    Please let me know how to change the javascript function, to include images in the response as well as text, thank you.
    Last edited by vortexer; 05-07-2007 at 03:58 AM.

  4. #4
    Join Date
    Apr 2007
    Posts
    209
    Basically I'm just trying to call the image in the page, not any text at all. So I think I can get rid of the text commands in the javascript and do something like this instead. But I think there is something missing in the getelement by id, like a src. command or something? Anyone know how to take an image from a php page and stick it in an id? I'm open to all suggestions. Thanks.


    if (xmlobject.readyState==4) {
    document.getElementById('T1').src ?????????
    Last edited by vortexer; 05-07-2007 at 06:39 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles