这是我的zend控制器
这就是我打电话给我的服务
请教我如何。这一点很重要 !非常感谢你
答案 0 :(得分:0)
看起来像你在那里做了一些额外的工作。我在ZF1和ZF2中都是这样做的:
PHP
// notice 'searchteams' is lowercased. There's been problems in the past
// when camelcasing action names, by default I believe ZF is looking for
// a lowercase action name unless you've configured it otherwise
public function searchteamsAction()
{
// make sure this is an ajax request (this is a method I usually write, if
// Zend has one you could use that here)
if ($this->isXmlHttpRequest())
{
// instantiate model, get the results, good
// disabling view and layout, good
// headers, never really had an issue that needed the headers to be set here
// would simply have..
echo json_encode($res);
}
}
JS:在AJAX调用的成功方法中,我这样做:
success : function (data){
// parse the json
var parsed_data = $.parseJSON(data);
console.log(parsed_data);
// do stuff with parsed_data
}
希望有所帮助。
答案 1 :(得分:0)
在return var_dump($res);
$this->_response->setHeader(...
检查您的数据
如果您有数据,请尝试添加$this->_response->setHeader('Content-Type', 'application/json', true);
如果不起作用,请尝试替换
$this->_response->setHeader(...);
$this->_response->setHeader(...);
$this->_response->setHeader(...);
$this->_response->setHeader(...);
和echo Zend_Json::encode($res);
仅限
return $this->_helper->json($res);
你也可以看到jQuery方面的错误:
error: function(xhr, status, error) {
alert("error status: " + status);
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
我希望它会对你有所帮助:)。