PHP Ajax example
PHP Ajax example
Here is a simple PHP Ajax example webpage. We are using three files to complete this script
- First one is an HTML file named Test.html
- Second is a javascript file with the name clienthint.js
- Third is a php file with the name Tutorialz.php
So let us start with the HTML page. It contains a simple HTML form and a link to a JavaScript.
Test.html code looks like this
<script type='text/javascript' src='clienthint.js'></script> <input type='text' id='txt1' onkeyup='showHint(this.value)'/> <p>Suggestions: <span id='txtHint'></span></p>
Below is the javascript part which in turn calls XMLHTTP request from the page Test.html to the Tutorialz.php page.
This is the JavaScript code, stored in the file “clienthint.js“:
var xmlHttp function showHint(str) { if (str.length==0) { document.getElementById('txtHint').innerHTML=''; return; } xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ('Your browser does not support AJAX!'); return; } var url='tutorialz.php'; url=url+'?q='+str; url=url+'&sid='+Math.random(); xmlHttp.onreadystatechange=stateChanged; xmlHttp.open('GET',url,true); xmlHttp.send(null); } function stateChanged() { if (xmlHttp.readyState==4) { document.getElementById('txtHint').innerHTML=xmlHttp.responseText; } } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject('Msxml2.XMLHTTP'); } catch (e) { xmlHttp=new ActiveXObject('Microsoft.XMLHTTP'); } } return xmlHttp; }
The AJAX Server Page -PHP
There is no such thing as an AJAX server. AJAX pages can be served by any internet server.
Code inside “tutorialz.php” page checks an array of names and returns the corresponding names to the client:
Note: Code below is tutorialz.php
<?php // Fill up array with names $a[]='Google'; $a[]='Yahoo'; $a[]='Hotmail'; $a[]='Java'; $a[]='PHP'; $a[]='Asp'; $a[]='Ajax'; $a[]='Javascript'; $a[]='Ruby'; $a[]='Ecllipse'; $a[]='Dreamweaver'; $a[]='Flash'; $a[]='Photoshop'; $a[]='Fireworks'; $a[]='Flex'; $a[]='hass'; $a[]='marcelo'; $a[]='luciano'; $a[]='thiago'; $a[]='pallero'; $a[]='mozin'; $a[]='angush'; $a[]='gary'; $a[]='mike'; $a[]='perotti'; $a[]='michael'; $a[]='angelo'; $a[]='remoiv'; $a[]='asne'; $a[]='jack'; //get the q parameter from URL $q=$_GET['q']; //lookup all hints from array if length of q<0 if (strlen($q) < 0) { $hint=''; for($i=0; $i { if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q)))) { if ($hint=='') { $hint=$a[$i]; } else { $hint=$hint.' , '.$a[$i]; } } } } // Set output to 'no suggestion' if no hint were found // or to the correct values if ($hint == '') { $response='no suggestion'; } else { $response=$hint; } //output the response echo $response; ?>
Save all these files in the same location and call the script from your localserver using the URL (http://localhost/Test.html)
PHP Ajax example,
Incoming search terms:
- yii select2 ajax (3)
- Ajax php page (2)
- ajax paging scripts php (1)
- select2 ajax mysql (1)
- select2 php (1)
- The AJAX Server Page in php (1)
- yii dropdownlist ajax onchange (1)
- yii select2 ajax onchange add new entry (1)
- yii select2 example (1)
- Select2 Ajax Example (1)
- php mysql ajax Pagination after submit (1)
- php ajax (1)
- musick1l (1)
- jqgrid ajax servlet (1)
- Filter data using PHP AJAX (1)
- exsample Yii ajax (1)
- AjaxPageWithPHP-BestOnlineSolutionForWebsiteScriptsAndTutorials (1)
- ajax with php pages (1)
- Ajax Paging yii (1)
- yii TbSelect2 data get ajax (1)
nice website keep going….
hmm wooww
yup..
good one..
A good website with good inputs….hats off
a coool……..site
HMM
best of its kind
a nice one..
fine
not bad..
http://community.fitnessanywhere.com/members/vbest12.aspx – christina milian nude christina milian nude
a nice one
Good ajax stuff and php
cool site
maudg3 http://google.com