PhpTips.im - Everything about php - Download CMS, find tips and tricks, code snippetz, classes and more and more...
Bookmark this page !
   

Articles

    Home » Articles » PHP/AJAX » PHP code and the complete AJAX example
Published on : 04.05.2010 Category : PHP/AJAX Viewed : 53 times.

Implementing the server side functionality is very simple compared to the client side. In the PHP code we just need to check the $_GET  super-global array. Afterwards convert it to uppercase and echo the result. So the PHP code is this:

Code:


   1.
      <?php
   2.
      if (isset($_GET['inputText']))
   3.
      echo strtoupper($_GET['inputText']);
   4.
      ?>

Javascript F1

That's really short, isn't it?

At least you can find the complete client and server code below.

Client:

Code:


   1.
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   2.
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   3.
      <html xmlns="http://www.w3.org/1999/xhtml">
   4.
      <head>
   5.
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   6.
      <title>Ajax - PHP example</title>
   7.
      </head>
   8.
      
   9.
      <body>
  10.
      
  11.
      <script language="javascript" type="text/javascript">
  12.
      <!--
  13.
      // Get the HTTP Object
  14.
      function getHTTPObject(){
  15.
      if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
  16.
      else if (window.XMLHttpRequest) return new XMLHttpRequest();
  17.
      else {
  18.
      alert("Your browser does not support AJAX.");
  19.
      return null;
  20.
      }
  21.
      }
  22.
      
  23.
      // Change the value of the outputText field
  24.
      function setOutput(){
  25.
      if(httpObject.readyState == 4){
  26.
      document.getElementById('outputText').value = httpObject.responseText;
  27.
      }
  28.
      
  29.
      }
  30.
      
  31.
      // Implement business logic
  32.
      function doWork(){
  33.
      httpObject = getHTTPObject();
  34.
      if (httpObject != null) {
  35.
      httpObject.open("GET", "upperCase.php?inputText="
  36.
      +document.getElementById('inputText').value, true);
  37.
      httpObject.send(null);
  38.
      httpObject.onreadystatechange = setOutput;
  39.
      }
  40.
      }
  41.
      
  42.
      var httpObject = null;
  43.
      
  44.
      //-->
  45.
      </script>
  46.
      
  47.
      <form name="testForm">
  48.
      Input text: <input type="text" onkeyup="doWork();" name="inputText" id="inputText" />
  49.
      Output text: <input type="text" name="outputText" id="outputText" />
  50.
      </form>
  51.
      </body>
  52.
      </html>

Javascript F1

Server:

Code:


   1.
      <?php
   2.
      if (isset($_GET['inputText']))
   3.
      echo strtoupper($_GET['inputText']);
   4.
      ?>

Javascript F1



Add this article in :

 

There is not yet any comment !



238 Rating: 2.0/10 (1 vote cast)

 

 Members
Log In !
Email Address :

Password :


Change my passowrd !
Sign Up !
We have : 3 members.
Latest member : albans
 
 Last Posts
 
 Advertising
 
©PhpTips.im 2010
Powered by PikaCMS.
Quick Links :
Home | Browse all articles | Downloads | Terms of Use
RSS RSS 2.0 : Articles | Downloads ATOM : Articles | Downloads