Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Error in developing my first AJAX example. . . .

Error in developing my first AJAX example. . . .

Scheduled Pinned Locked Moved JavaScript
helpjavascriptphphtmltools
4 Posts 4 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    khurram_shahzad
    wrote on last edited by
    #1

    hi ... i m trying to make this me first simple AJAX example using PHP that shows message from PHP on clicking Button in HTML page .... but this case some prolem ... that is when click on button to show message then nothing is happen .... is also check WAMP ... so any idea or suggestion !!!! HTML CODE IS,

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>MyFirstAJAXProram</title>

    </head>
    <body>
    <script type="text/javascript">
    function JavaFunction() {
    var xmlhttp;
    if(window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
    } else {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
    if(xmlhttp.readystate == 4) {
    document.timerForm.time.value = xmlhttp.responseText;
    }
    }
    xmlhttp.open("GET", "phpfile.php", true);
    xmlhttp.send(null);
    }
    </script>
    <form name="timerForm">
    <input type="button" onclick="JavaFunction()"; />
    Time: <input type="text" id="timer" name="time" value="00:00:00" readonly="readonly" />
    </form>
    </body>
    </html>

    PHP CODE;

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>
    <?
    echo("KHURRAM SHAHZAD");
    ?>
    </body>
    </html>

    I found one another problem is that php file also not run when i try to run it directly..... :(

    L M 2 Replies Last reply
    0
    • K khurram_shahzad

      hi ... i m trying to make this me first simple AJAX example using PHP that shows message from PHP on clicking Button in HTML page .... but this case some prolem ... that is when click on button to show message then nothing is happen .... is also check WAMP ... so any idea or suggestion !!!! HTML CODE IS,

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>MyFirstAJAXProram</title>

      </head>
      <body>
      <script type="text/javascript">
      function JavaFunction() {
      var xmlhttp;
      if(window.XMLHttpRequest) {
      xmlhttp = new XMLHttpRequest();
      } else {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange=function() {
      if(xmlhttp.readystate == 4) {
      document.timerForm.time.value = xmlhttp.responseText;
      }
      }
      xmlhttp.open("GET", "phpfile.php", true);
      xmlhttp.send(null);
      }
      </script>
      <form name="timerForm">
      <input type="button" onclick="JavaFunction()"; />
      Time: <input type="text" id="timer" name="time" value="00:00:00" readonly="readonly" />
      </form>
      </body>
      </html>

      PHP CODE;

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Untitled Document</title>
      </head>

      <body>
      <?
      echo("KHURRAM SHAHZAD");
      ?>
      </body>
      </html>

      I found one another problem is that php file also not run when i try to run it directly..... :(

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Is PHP configured correctly[^]?

      I are Troll :suss:

      S 1 Reply Last reply
      0
      • L Lost User

        Is PHP configured correctly[^]?

        I are Troll :suss:

        S Offline
        S Offline
        Shantanu Gupta 1337
        wrote on last edited by
        #3

        :wtf: he just mentioned running a php directly. Solution: 1) Even though WAMP is installed on ur system, it might not be configured properly, refer to the prev post 2) You are running files from the folder. instead, add "Listen 127.0.0.1:80" in ur httpd.conf (apache config file), then open any browser and type "localhost" in address and hit enter. also rename the html file to index.html so it is served to the browser without and explicit input. 3) "I ran php directly" is the fastest way to achieve defame on any php forum.. also, a starter tip: never use short php tag (", i learnt this the hard way :/ -- Modified Saturday, October 23, 2010 5:21 PM

        1 Reply Last reply
        0
        • K khurram_shahzad

          hi ... i m trying to make this me first simple AJAX example using PHP that shows message from PHP on clicking Button in HTML page .... but this case some prolem ... that is when click on button to show message then nothing is happen .... is also check WAMP ... so any idea or suggestion !!!! HTML CODE IS,

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>MyFirstAJAXProram</title>

          </head>
          <body>
          <script type="text/javascript">
          function JavaFunction() {
          var xmlhttp;
          if(window.XMLHttpRequest) {
          xmlhttp = new XMLHttpRequest();
          } else {
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          }
          xmlhttp.onreadystatechange=function() {
          if(xmlhttp.readystate == 4) {
          document.timerForm.time.value = xmlhttp.responseText;
          }
          }
          xmlhttp.open("GET", "phpfile.php", true);
          xmlhttp.send(null);
          }
          </script>
          <form name="timerForm">
          <input type="button" onclick="JavaFunction()"; />
          Time: <input type="text" id="timer" name="time" value="00:00:00" readonly="readonly" />
          </form>
          </body>
          </html>

          PHP CODE;

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>Untitled Document</title>
          </head>

          <body>
          <?
          echo("KHURRAM SHAHZAD");
          ?>
          </body>
          </html>

          I found one another problem is that php file also not run when i try to run it directly..... :(

          M Offline
          M Offline
          moocr com
          wrote on last edited by
          #4

          if(xmlhttp.readystate == 4 && xmlhttp.status==200) {
          document.timerForm.time.value = xmlhttp.responseText;
          }

          may be you lost the xmlhttp.status==200. moocr.com

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups