0
我的Zend控制器是象下面這樣:的Zend控制器Ajax調用面對錯誤
public function deleteAction()
{
$this->_helper->layout->disableLayout();
$id = (int)$this->_request->getPost('id');
$costs = new Application_Model_DbTable_Costs();
if($costs->deleteCosts($id)){
$this->view->success = "deleted";
}
}
而且我是個使用發佈數據的AJAX調用是:
$.ajax({
dataType: 'json',
url: 'index/delete',
type: 'POST',
data:id,
success: function() {
alert("success");
},
timeout: 13*60*1000,
error: function(){
console.log("Error");
}
});
而在我delete.phtml代碼如:
<?php
if($this->delete === true):
echo 'true';
else:
echo 'Sorry! we couldn\'t remove the source. Please try again.';
endif;
?>
響應返回html。
它是我第一個使用Zend Framework的項目。 在此先感謝。
非常感謝,它工作正如你所說的,但是當我使用$ .ajax()時,它返回undefined作爲data.success.Can你解釋了什麼是錯的?它會對我有幫助,或者你可以共享一個鏈接如何jquery ajax調用zend.Thanks提前:)謝謝:) – mushfiq 2011-06-13 07:08:27
得到了解決方案,我傳遞的數據格式錯誤,它應該是數據:{「id」:id},它的工作:)謝謝 – mushfiq 2011-06-13 11:12:15