I'm getting a variable inside my catch (for when a web service call fails) statement and attempting to use json_encode on it:
try {
WebServices::create($this->nameWS);
}
catch (Exception $e) {
$tr = $e->getTrace();
$x = $tr[3];
json_encode($x);
}
$x
contains a string.
This catch statement sends me to the error section of my $.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.logging the dataError
parameter returns a huge long list of rubbish, none of which is relevant to this variable.
I have seen it is possible to send a json_encoded variable to JS, but never inside an error block of an ajax return - is there an easy way to get this variable here? Thanks guys.