2013-06-04 13:20
采纳率: 100%
浏览 65


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 {
catch (Exception $e) {                  
   $tr = $e->getTrace();
   $x = $tr[3];

$x contains a string.

This catch statement sends me to the error section of my $.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.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题