0
我对Zend Ajax有一些问题。这是我的js代码:Ajax调用不显示响应 - Zend Framework
function deleteNewsCategory(cId) {
var conf = confirm("Are you sure you want to delete the item?");
if(conf) {
$.ajax({
dataType: 'json',
url: '/ajax/deletenewscategory',
type: 'POST',
data: {
cId : cId
},
success: function (response) {
alert(response);
}
});
}
}
这是我AjaxController:
public function init() {
$this->_helper->ajaxContext->addActionContext('deletenewscategory', 'json')
->initContext();
}
public function deletenewscategoryAction() {
if ($this->getRequest()->isPost()) {
echo $this->_request->getPost('cId');
}
}
我添加deleteNewsCategory功能提交按钮,但是当我点击这个按钮,会出现确认信息,然后点击好的,我什么都没看到?
不要有JavaScript错误,CID才有价值,我添加警报(1)成功:函数(响应){警报(1); ...,但没有看到什么? – Defense 2012-08-12 19:56:36
如果HTTP响应不包含有效的JSON(例如它有HTML),那么你的jQuery回调将不会被调用。尝试从Ajax请求中删除'dataType',或者使用wireshark嗅探完整的HTTP响应并查看返回的内容。 – drew010 2012-08-12 20:00:11
好吧我安装Wireshark,我需要在http中搜索? – Defense 2012-08-12 20:26:41