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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Location
    Vermont
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Php, html request not working

    I can not for the life of me get this code to work with my html file, why? This is saved as a before7.html file. The below is not everything in this code but it is very long so didn't think you would want all of it here.

    PHP Code:
    <style>
    .
    displaybox {
    width:150px;
    background-color:#ffffff;
    border:2px solid #000000;
    padding:10px;
    font:24px normal verdanahelveticaarialsans-serif;
    }
    </
    style>
    <
    script language="JavaScript" type="text/javascript">
    function 
    getXMLHTTPRequest() {
    try {
    req = new XMLHttpRequest();
    } catch(
    err1) {
      try {
      
    req = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (
    err2) {
        try {
        
    req = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (
    err3) {
          
    req false;
        } 
      } 
    }
    return 
    req;
    }

    var 
    http getXMLHTTPRequest();
      
    function 
    getServerTime() {
      var 
    myurl 'telltimeXML.php';
      
    myRand parseInt(Math.random()*999999999999999);
      var 
    modurl myurl+"?rand="+myRand;  
      
    http.open("GET"modurltrue);
      
    http.onreadystatechange useHttpResponse;
      
    http.send(null);
    }

    function 
    useHttpResponse() {
       if (
    http.readyState == 4) {
        if(
    http.status == 200) { 
           var 
    timeValue http.responseXML.getElementsByTagName("timenow")[0]; 
           
    document.getElementById('showtime').innerHTML timeValue.childNodes[0].nodeValue;
        }
      } else {
      
    document.getElementById('showtime').innerHTML '<img src="anim.gif">';
      }
    }
    </script>
    </head>
    <body style="background-color:plum" onLoad="getServerTime()">
    <center>
    <h1>Ajax Demonstration</h1>
    <h2>Getting the server time without page refresh</h2>
    <form>
    <input type="button" value="Get Server Time" onClick="getServerTime()">
    </form>
    <div id="showtime" class="displaybox"></div>
    </center> 
    And I have this php code saved as clock.php

    PHP Code:
    <?php 
    header
    ('Content-Type: text/xml');
    echo 
    "<?xml version=\"1.0\" ?><clock1><timenow>".date('H:i:s')."</timenow></clock1>"
    ?>
    Last edited by Inigoesdr; 10-21-2012 at 05:19 AM.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    What is a before 7.html?

    This in red
    <?php
    header('Content-Type: text/xml');
    echo "<?xml version=\"1.0\" ?><clock1><timenow>".date('H:i:s')."</timenow></clock1>";
    ?>
    Turns the page into xml and I get errors when run. Remove it and the php echos the so called time.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    It may be that you have php short tags turned on in your php.ini file.

    With php short tags, you open php code with <?php OR <?

    When you then use xml in your php, <?xml contains <? doesn't it. Now, it shouldn't make any difference when being echoed as a string but I found php could be a bit screwy with this issue (such as reading an xml template from a file into a string using file_get_contents(() so you might want to look into turning off short tags and see if that works.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Posting Permissions

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