php无法返回json格式怎么办
php无法返回json格式的解决办法:1、判断error的具体原因,执行“var a=JSON.stringify(error);alert(a);”代码;2、修改php代码,执行“var b= eval("(" + data + ")");”代码即可。

本教程操作环境:Windows10系统、PHP8.1版、DELL G3电脑
php无法返回json格式怎么办?
php无法返回标准JSON格式:导致的$.ajax返回的数据无法执行success的解决方案
JSON的标准格式:{“键”:“值”,“键”:“值”}
一、前端提交代码,如下
$.ajax({
type: "post",
url: "index.php?m=Index&a=accessIn&act=access",
async: true,
data: {
login_access: $('#login_access').val()
},
dataType: "text",
success: function (data) {
if (data.codeId == "0") {
alert(data.err);
} else {
alert(data.err);
window.location.href = "index.php?m=Index&a=lockData";
}
},
error:function(error){
var a=JSON.stringify(error);
alert(a);
}});
登录后复制

