這段代碼有什麼問題?我無法驗證 '數據':
$.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