Php $.ajax没有带来我的json\u编码
Returno json_编码没有返回任何内容 这是js控制器,我想返回jsonPhp $.ajax没有带来我的json\u编码,php,jquery,ajax,Php,Jquery,Ajax,Returno json_编码没有返回任何内容 这是js控制器,我想返回json $.ajax({ url: 'controll/busqueda.php', data: { format: 'json', "precio_min": "", "precio_max": "", "rate": "", "asignatura": "" }, success: function(reto
$.ajax({
url: 'controll/busqueda.php',
data: {
format: 'json',
"precio_min": "",
"precio_max": "",
"rate": "",
"asignatura": ""
},
success: function(retorno) {
alert(retorno.profesores);
},
error: function() {
alert("aaaaa");
},
type: 'GET'
});
这是一个php文件,我在其中调用模型db,$retrono是一个数据库中的stdClass,我把它放在数据库中
if($precio_max != "" || $precio_min != ""){
$retorno = $busqueda->profesor_precio($precio_min,$precio_max);
}else{
if($rate != ""){
$retorno = $busqueda->profesor_rate($rate);
}else{
if($asignatura != ""){
$retorno = $busqueda->profesor_asig($asignatura);
}else{
$retorno = $busqueda->profesor();
}
}
}
echo json_encode($retorno, true);
1您的服务器必须返回标题为:Content-type:application/json的正确响应。您可以使用以下代码在php中实现:
header('Content-type: application/json');
您必须在任何回音之前发送此标题
2为ajax请求设置数据类型属性。例如:
$.ajax({
url: 'controll/busqueda.php',
dataType: 'json',
data: {
param: 'value'
},
success: function(retorno) {
alert(retorno.profesores);
},
type: 'GET'
});
3确保对controll/busqeda.php的请求返回有效的json数据。查看您的回复http://yourhost.name/controll/busqueda.php 它返回的是有效的json吗?您是否在浏览器的开发工具中查看过AJAX请求/响应?哦,retrono.profesores的结果总是未定义的,应该是和arraySo-这不是您的AJAX,是你的PHP不起作用。当我测试它时,从localhost/调用它。。。它打印了所有应该打印的内容我做了所有这些,但没有工作它现在只给出了一个错误这应该是我的json当我在localhost/../busqueda.php{respuesta:200,info:Profesores Encontrados,Profesores:[{id_教授:1,姓名:Guillermo,电子邮件:memonte@gmail.com你错过了吗在响应的末尾。这只是一个输入错误吗?请尝试url:“/controll/busqeda.php”而不是url:“controll/busqeda.php”执行JavaScript代码的html页面的地址是什么?它与您对busqeda.php脚本的请求位于同一域中?请显示html和json请求的完整url。