【发布时间】:2013-06-20 01:59:09
【问题描述】:
我想在 javascript 中出现条件后更新我的数据库。我现在做的是这样的:
<a href="#" onclick="hello()">Update me</a>
<srcipt>
function hello(smthing)
{
if(smthing == true)
{
<?php //Update database table ?>
}
}
<script>
我还尝试根据 w3schools (http://www.w3schools.com/ajax/ajax_example.asp) 中的示例更新我的表格:
<script>
function hello(smthing)
{
if(smthing==true)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","db_update.php",true);
xmlhttp.send();
}
}
</script>
在第一种情况下,即使变量 smthing = false,它也会更新我的表(但如果我在 if 中输入 alert("hi"),则仅当 'smthing' 为 true 时才会显示警报。
在第二种情况下,什么也没有发生。 :/
有什么帮助或指导吗?
【问题讨论】:
-
让我们知道你可以使用 jquery。
标签: php javascript mysql ajax database