这段代码有什么问题?我无法验证 '数据':
$.post('http://localhost/do.php', function(data)
{
if (data == "success")
{
//do something... but this line never hit!
}
});
我也试过,
alert(data);
,但有一个空的警告框!
成功的do.php,回声的 “成功”
echo "success";
确定..这里是完整的原始代码:
<script type="text/javascript">
function confirm_delete(id)
{
var r=confirm("Are you sure you want to delete?");
if (r==true)
{
var path = "http://localhost/site/index.php/delete/" + id;
$.post(path, function(data)
{
if (data=='success')
{
$('#'+id).remove();
}
else
{
alert("Unable to delete, try again!");
}
});
}else
{
//cancel
}
}
//-->
</script>
在HTML,会有很多的职位与他们相应的ID在div中,由数据库中的php奠定,有点像这样:
<div id="1">
<div class='post'>Something</div>
<a href="#"><img src="styles/plugins/buttons/icons/cross.png" height="8" width="8" title="Remove" onclick="confirm_delete(1)"/></a>
</div>
<div id="2">
<div class='post'>Something</div>
<a href="#"><img src="styles/plugins/buttons/icons/cross.png" height="8" width="8" title="Remove" onclick="confirm_delete(2)"/></a>
</div>
<div id="3">
<div class='post'>Something</div>
<a href="#"><img src="styles/plugins/buttons/icons/cross.png" height="8" width="8" title="Remove" onclick="confirm_delete(3)"/></a>
</div>
在PHP中没有什么现在...它只是打印成功...我做了这样的测试。
echo "success";
当直接去链接时,它打印“成功”。 '数据'是一个字符串吗?我的意思是这是正确的?
if (data=='success')
请求来自哪里? – 2010-07-08 18:06:59
http://localhost/do.php输出是什么?使用Firebug检查HTTP请求和响应。 – 2010-07-08 18:10:55
回声“成功”; – esafwan 2010-07-08 18:14:37