JavaScript不能在其自己的数据库处理,它只是可以告诉浏览器做什么,服务器提交的页面浏览器后,才加载。所以我想你必须使用AJAX。这是一个使用非常简单的jQuery:
...
$.post('process.php', {id:curid, date : when}, function(data) {
alert(data);
//data contains all output from process.php,
//either in json-format if you jsonencode a results-array
//or just a simple string you echo in the php
return false; //prevent from reloading the page
});
...
你process.php可能类似于:
<?php
$curid = $_POST['id'];
$when = $_POST['date'];
//run the query
echo jsonencode($results_array);
//or check if query succeeded and echo e.g. 'ok' or 'failed'
?>
你的想法...;)
//编辑:
您应该使用jQuery UI作为对话框以避免评论中所述的消息。这可能是这样的:
<div id="dialog_box" style="display: none;">
Really delete?
</div>
$('#dialog_box').dialog({
title: 'Really delete this stuff?',
width: 500,
height: 200,
modal: true,
resizable: false,
draggable: false,
buttons: [{
text: 'Yep, delete it!',
click: function(){
//do the post
}
},
{
text: 'Nope, my bad!',
click: function() {
$(this).dialog('close');
}
}]
});
男人,两个Cartmans是太多的一个职位:D(对这个问题完全无关的评论) – tugberk
@tugberk大声笑,甚至没有注意到,但那是......呃......“拧你们,我是回家!' :-D – Quasdunk
当我这样做的时候,它可以工作,但我收到一条消息,说明是否再显示额外的警报框。我该如何摆脱?其他人是否会收到类似的消息? – cbr0wn