0
尝试访问由ajax发送给php的JSON变量时遇到问题。 EnvíoLA varible “邮报”:请求的JSON解析失败(ajax)+ zf2
<script>
$("#recuperar").click(function() {
var url1 = "<?php echo $this->url('login',array('controller'=>'Login', 'action'=>'recuperar')) ?>";
var consulta = $("#correo").val();
$.ajax({
type: "POST",
url: url1,
data: {"correo": consulta},
dataType: "json",
beforeSend: function() {
},
error: function (jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
},
success: function (data) {
$("#mostrar").empty(data);
$("#mostrar").append(data['error']);
}
});
});
我的控制器:
public function recuperarAction() {
$em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
if ($this->request->isXmlHttpRequest()) {
$correo = $_REQUEST['correo'];
print_r($correo);
当我尝试print_r($email)
返回我这个错误:请求JSON解析失败。
这也适用于如果到print_r(some_value)
,如果我尝试打印任何数据会返回相同的错误。
感谢帮助,对不起我的英语是纯正的谷歌翻译
感谢您的回应,您可能会向我解释如何为Json数据配置应用程序。非常感谢,真的是ZF2和Doctrine2的新手。 – 2015-04-07 16:24:50