【发布时间】:2011-03-03 15:35:40
【问题描述】:
所以我还有一个问题,
我正在尝试让 AJAX 脚本工作,但点击后页面将重新加载但无法更新数据库字段。
我使用的代码我已经为网站上的其他类似脚本工作,但由于某种原因,使用相同的代码不起作用,使用的代码如下;
将调用发送到 AJAX 的 HTML 代码:
<input onClick="read('<? echo $id; ?>')" id="read" name="read" type="checkbox" value="1" style="position:relative; top:2px; width: auto">
确认用户选择并发送到表单处理文件的代码:
function read(ID) {
if(confirm('Are you sure you have read this carefully, you will not be alerted again "' + ID + '" ?')) {
$.get('http://<? echo ROOT . ADMIN . INCLUDES; ?>formHandling.php', { read: ID }, function(data) {
window.location.href = 'http://<? echo $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].""; ?>';
});
}
return false;
}
最后是处理 SQL 查询的代码:
if (isset($_GET['read'])) {
// Pass the GET data and associate them to variables
$read = trim($_GET['read']);
$query = "UPDATE cms_motd SET read='$read' WHERE id='1'";
$result = mysql_query($query)or die("Database query died: " . mysql_error());
unset($_GET['readConfirm']);
}
提前感谢所有帮助。
问候,
丹。
【问题讨论】:
标签: php jquery mysql html ajax