Get values of called file
I am calling a .php file in this code. In the file "fetchvalues.php", I am fetching results from the database and want to return the column values back to the calling JQuery function and display them on HTML controls of my page.
How to do so?
$(document).ready(function() {
$("#Edit").click(function() {
$.get('fetchvalues.php', null, function() {
alert('reached');
});
});
});
Edited: Code: fetchvalues.php
<?PHP
//Get selected row's RecordID column value
$SelectedRowID = $_GET['UpdateRecordID'];
//Open Connection
$connection = mysql_connect("localhost:3306", "abcd", "abcd");
mysql_select_db("pglobal", $connection);
//Prepare query to retrieve results
$FetchResultsQuery = "SELECT * FROM listing WHERE recordid=" . $SelectedRowID;
try
{
$result = mysql_query($FetchResultsQuery);
$row = mysql_fetch_row($result);
if ($row)
{
$PostedDate = date('d.M.Y', strtotime($row[0]));
$Places = html_entity_de开发者_开发技巧code($row[1]);
$Company = html_entity_decode($row[2]);
$Designation = html_entity_decode($row[3]);
$ProjectDetails = html_entity_decode($row[4]);
$DesiredCandidate = html_entity_decode($row[5]);
$HRName = html_entity_decode($row[6]);
$HRContact = html_entity_decode($row[7]);
$Email = html_entity_decode($row[8]);
$_SESSION['WorkMode'] = 'Edit';
$_SESSION['DataToBeEdited'] = $PostedDate .'+'. $Places .'+'. $Company .'+'. $Designation .'+'. $ProjectDetails .'+'. $DesiredCandidate .'+'. $HRName .'+'. $HRContact .'+'. $Email;
}
else
{
$_SESSION['DataToBeEdited'] = "";
return;
}
}
catch(exception $err)
{
echo $err;
}
?>
If i could understand, you need back the response then:
$(document).ready(function(){
$("#Edit").click(function(){
$.get('fetchvalues.php', null, function(response){
alert(response);
});
});
});
You could generate JSON data, and handle it with jquery - also see the last of the examples at http://docs.jquery.com/Ajax/jQuery.get#urldatacallbacktype
精彩评论