Fetching records with AJAX

Fetching records with AJAX

ajax framework
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:

 

$.Ajax({
  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.

<html>
<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){
$(“#dataContainer”).html(myResponse);
//alert(response);
}
});
});
});
</script>
<body>
<strong>The Records Retrieved</strong>
<table border=”1″ align=”center”>
<tr>
<td> <input type=”button” id="myButton" value=”Show me the records” /> </td>
</tr>
</table>
<div id="dataContainer" align="center">
</div>
</body>
</html>

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

<?php
$myConnection=mysql_connect(“localhost”,”root”,””);
if (!$myConnection)
{
die(‘Connection failed: ‘ . mysql_error());
}
?>
<?php
include(“myConnection.php”);
mysql_select_db(“somedatabase”,$con);
$resultSet=mysql_query(“select * from sometable”,$con);

echo “<table border=’1′ >
<tr>
<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>”;
?>

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