Angelo's Corner

PHP and AJAX

May 26, 2010

Ajax (shorthand for asynchronous JavaScript and XML[1]) is a group of interrelated web development techniques used on the client-side to create interactive web applications.

-we use AJAX for the dynamic controls of our web applications…so this is morely on the client side of the application..

and the server side language is PHP..

so combining the two we can build a several web applications…isn’t it?..

 

so that is why…

i have a very simple program demonstrating the PHP and AJAX coding..

 

 1. assuming we have file test.php

 <!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=iso-8859-1″ />
<title>Reverse using Ajax</title>
</head>
<script language=”javascript”>
    function doReverse(){
        var str=document.getElementById(”txtStr”).value;
        var httpObject=getHTTPObject();
        if(httpObject!=null){
            httpObject.open(”GET”,”reverse.php?str=”+str,true);
            httpObject.send(null);
            httpObject.onreadystatechange=
                function updateReverse(){
                    var responseStr;
                    if(httpObject.readyState==4){
                        responseStr=httpObject.responseText;
                        document.getElementById(”txtReverse”).value=responseStr;
                        document.getElementById(”txtStr”).value=responseStr;
                    }                
                }
            
       
        }
       
    }
   
    function getHTTPObject(){
        if(window.ActiveXObject)
            return new ActiveXObject(”Microsoft.XMLHTTP”);           
        else if(window.XMLHttpRequest)
            return new XMLHttpRequest();
        else{
            alert(”Your browser does not support AJAX”);
            return null;
        }
       
       
    }
</script>

<body>
<table width=”392″ border=”0″ cellspacing=”0″ cellpadding=”0″>
  <tr>
    <td width=”184″>String:</td>
    <td width=”208″><input id=”txtStr” type=”text” size=”40″ /></td>
  </tr>
  <tr>
    <td>String in Reverse:</td>
    <td><input name=”text” type=”text” id=”txtReverse” size=”40″ /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type=”button” name=”cmdReverse” value=”Reverse” onclick=”doReverse();” /></td>
  </tr>
</table>
</body>

</html>

 

 2.we have also file reverse.php

<?php
   
$str=$_GET[”str”];
echo strrev($str);

?>

 

so this is the very simple way implementing AJAX in PHP..

hope it helps..

 

 

Posted by angelohere at 2:38 pm | permalink | Add comment

     

September 2010
M T W T F S S
« May    
 12345
6789101112
13141516171819
20212223242526
27282930  

About Me

I am Angelo F. Matildo, my nickname is ngel. Currently, I am a systems developer in a company. This blog is primarily for me to post my researches,my some learnings,sharing and some random ideas. Most likely I'm not going to be commenting on things happening... As such it will most likely not be updated very often...

Message Board

mia:

hello mahal ko… congratulations!

yance_angelo::

yance pg.leave ug message dri yance..
mwahmwahmwah

angelohere:

asa ka pa?

angelo:

hello..

support:

Congratulations, you’ve just completed the installation of this shoutbox.

support:

Hi! Your shoutbox is working fine!

Leave a message ▼

Sponsored Links

Recent Photo

Strange Google Maps

Subscribe

Technorati
Bloglines