为什么下面的代码不能正常工作?我只需要通过点击btn上的javascript id内容发布。这段代码在许多其他情况下都能正常工作,但这里我使用的是twitter引导模式。谢谢。
<button id="<?php echo $id; ?>" class="btn btn-warning" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<span class="glyphicon glyphicon-trash"></span> delete id
</button>
<script type="text/javascript">
//delete id
$(document).on('click','.btn-warning',function(){
var element = $(this);
var del_id = element.attr("id");
var info = 'id=' + del_id;
if(confirm("are you sure ?")){
$.ajax({
type: "POST",
url: "page.php",
data: info,
success: function(){ window.location.href = "/logout.php"; }
});
}
return false;
});
</script>
PHP
if($_POST['id']){
$id=$_POST['id'];
$id = mysql_real_escape_string($id);
...发布于 2014-02-07 05:12:37
首先,我认为你应该在PHP中使用isset(变量):
if (isset($_POST['ID'])
{
...其次,它不起作用,因为您需要设置数据和一个键->值数组。
data: {id: "ID_NUMBER"}查看Jquery网站上的示例:https://api.jquery.com/jQuery.ajax/
我还建议使用唯一的ID属性或新的/唯一的类属性,然后使用它来添加onClick事件。
发布于 2014-02-07 21:46:28
info = {'id' : del_id };尝试以数组形式发送数据。
https://stackoverflow.com/questions/21613963
复制相似问题