我想在Zend Framework中使用jQuery。而我遇到的问题是当我试图将数据保存到数据库。尽管数据正在保存在数据库中,但始终接收到ajax错误。Zend应用程序jQuery ajax调用获取错误
,我使用添加数据控制器是象下面这样:
public function addAction()
{
// action body
$form = new Application_Form_Costs();
$form->submit->setLabel('Add');
$this->view->form = $form;
if($this->getRequest()->isPost())
{
$formData = $this->getRequest()->getPost();
{
if ($form->isValid($formData))
{
$costTitle = $this->_request->getPost('costTitle');
$costAmount = $this->_request->getPost('costAmount');
$costs = new Application_Model_DbTable_Costs();
if($costs->addCosts($costTitle, $costAmount))
{
echo "suces";
}
// $this->_helper->redirector('index');
}
else
{
$form->populate($formData);
}
}
}
}
,这是通过数据如下jQuery的:
$('#cost').submit(function(){
data = {
"cost_title":"cost_title",
"cost_amount":"cost_amount"
};
$.ajax({
dataType: 'json',
url: '/index/add',
type: 'POST',
data: data,
success: function (response) {
alert(response);
},
timeout: 13*60*1000,
error: function(){
alert("error!");
}
});
});
我总是得到错误。
这段代码有什么问题?
在此先感谢。
检查的萤火Ajax请求......是响应有效的JSON? http://jsonlint.com – gnarf 2011-06-10 11:58:45
获取整个js作为回应! – mushfiq 2011-06-10 12:13:46
你能粘贴你得到的错误吗? – 2011-06-10 12:18:05