下面的代码有一个按钮,它的onclick调用updatedb.php并显示其在div元素输出所谓的“结果”
<html>
<head>
<script type="text/javascript">
function UpdateDb()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("result").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","updatedb.php",true);
xmlhttp.send();
}
</script>
</head>
<body>
<button onclick='UpdateDb()'>Update</button>
<p> <span id="result"></span></p>
</body>
</html>
然后写updatedb.php
<?php
do mysql update here.
and echo the result you want to display.
?>
你需要为此使用ajax。 – hkutluay 2012-04-14 21:43:01