我在此代码中调用.php文件。在文件“fetchvalues.php”中,我从数据库中获取结果,并希望将列值返回给调用的JQuery函数,并将其显示在我页面的HTML控件上。
怎么做?
$(document).ready(function() {
$("#Edit").click(function() {
$.get('fetchvalues.php', null, function() {
alert('reached');
});
});
});
编辑: 代码: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_decode($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;
}
?>
答案 0 :(得分:1)
如果我能理解,那你需要回复:
$(document).ready(function(){
$("#Edit").click(function(){
$.get('fetchvalues.php', null, function(response){
alert(response);
});
});
});
答案 1 :(得分:0)
您可以生成JSON数据,并使用jquery处理它 - 另请参阅http://docs.jquery.com/Ajax/jQuery.get#urldatacallbacktype上的最后一个示例