我在我的 catch 语句中获取了一个变量(用于 Web 服务调用失败时),并尝试在其上使用json_encode:
try {
WebServices::create($this->nameWS);
}
catch (Exception $e) {
$tr = $e->getTrace();
$x = $tr[3];
json_encode($x);
}
$x
包含一个字符串。
这个 catch 语句将我发送到我的 $.ajax 的错误部分:
$.ajax({
type: 'POST',
url: 'index.php',
data: 'module=random&action=' + action + params,
dataType: 'json',
success: function(dataJson){
callbackServer(action, otherVars, dataJson);
callServer.isRun = false;
},
error : function(dataError) {
console.log("I want to get the $x variable here");
}
});
console.loggingdataError
参数返回一个巨大的垃圾列表,这些都与这个变量无关。
我已经看到可以将 json_encoded 变量发送到 JS,但永远不会在 ajax 返回的错误块内 - 有没有一种简单的方法可以在这里获取这个变量?多谢你们。