单击时,链接应运行从同一页面上的数据库中提取信息的 PHP 代码。
我已经使用 AJAX、表单和按钮实现了这一点,但我真的希望使用链接而不是按钮。
我已经设法使链接正常工作,但是 PHP 脚本创建的数据库中的表仅在浏览器刷新时闪烁一秒钟。
如何停止刷新以显示表格?
如果有任何帮助,我将不胜感激。
我的代码是:
<script language="javascript" type="text/javascript">
function myFunction(){
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser has Failed");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv1');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
document.proffForm.submit();
ajaxRequest.open("GET", "proff/all_proff.php");
ajaxRequest.send(null);
}
</script>
<form name='proffForm' >
<a href="#" onclick='myFunction()' >List All Professions</a>
</form>
<div id='ajaxDiv1'></div></p>
php
<?php
include '../dbc.php';
$allprof1 = mysql_query("SELECT *
FROM users
ORDER BY profession" );
$qry_result = mysql_query($allprof1) or die(mysql_error());
?>
<?php
$display_string = "<table border='1' cellpadding='5' width='100%' bordercolor='000099'border='solid'>";
$display_string .= "<tr align='left' bgcolor='009966'>";
$display_string .= "<th><span class='titlehdr3'>Profession</span></th>";
$display_string .= "<th><span class='titlehdr3'>Business Name</span></th>";
$display_string .= "<th><span class='titlehdr3'>Profile</span></th>";
$display_string .= "</tr>";
while($row = mysql_fetch_array($qry_result)){
$display_string .= "<tr>";
$display_string .= "<td><span class='tabs'>$row[profession]</span></td>";
$display_string .= "<td><span class='tabs'>$row[full_name]</span></td>";
$display_string .= "<td><span class='tabs'>$row[url]</span></td>";
$display_string .= "</tr>";
}
$display_string .= "</table>";
echo $display_string;
?>