Fetching records with AJAX

Posted by

Fetching records with AJAX

image credit:wikipedia.org

Fetching AJAX records is not as horrifying as Dracula movie.The most effective method to utilize AJAX to bring records from Table utilizing PHP : The accompanying is the case to see how to utilize AJAX (Javascript and XML) in PHP server side scripts. The utilization of AJAX in PHP is to perform halfway page postbacks. At last, AJAX is to enhance page execution a considerable measure. It utilizes Xmlhttprequest and Xmlhttpresponse protest as a part of request to process information.

The AJAX and jquery tag team

In addition to different preferences, one of my most loved peculiarities of jquery is its capacity to influence Ajax with almost no exertion. To make an Ajax call, you can do something like this:


  type: "POST",
  url: "myPage.php",
  data: "name=Adeel&location=Karachi",
  success: function(myWords){
    alert( "Work done: " + myWords );

In the event that you’ve created Ajax applications before without jquery, you’ll promptly see the quality here. jquery has put the greater part of the properties of Ajax into one basic Programming interface. You can control everything including the url,the caching,functionality etc. It’s absolutely delightful.

<script type=”text/javascript” src=”jquery-1.3.2.js”> </script>
<script type=”text/javascript”>
$(document).ready(function() {
$(“#myButton”).click(function() {
$.ajax({ // for page retrieval
type: “GET”,
url: “myPage.php”,
dataType: “html”, //try to retrieve html page
success: function(myResponse){
<strong>The Records Retrieved</strong>
<table border=”1″ align=”center”>
<td> <input type=”button” id="myButton" value=”Show me the records” /> </td>
<div id="dataContainer" align="center">

Insert that php script to make the connection with the database. This is myConnection.php

if (!$myConnection)
die(‘Connection failed: ‘ . mysql_error());
$resultSet=mysql_query(“select * from sometable”,$con);

echo “<table border=’1′ >
<td align=center> <b>Field1</b></td>
<td align=center><b> Field2</b></td>
<td align=center><b> Field3</b></td>

while($myRecord = mysql_fetch_row($resultSet))
echo “<tr>”;
echo “<td align=center>$myRecord[0]</td>”;
echo “<td align=center>$myRecord[1]</td>”;
echo “<td align=center>$myRecord[2]</td>”;
echo “</tr>”;
echo “</table>”;

Facebook Comments

Syed Adeel Ahmed
Analyst, Programmer, Educationist and Blogger at Technofranchise
Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.
Syed Adeel Ahmed on FacebookSyed Adeel Ahmed on GoogleSyed Adeel Ahmed on InstagramSyed Adeel Ahmed on Twitter