Revision history [back]

click to hide/show revision 1
initial version

answered 2016-07-25 07:59:59 +0800

cor3000 gravatar image cor3000

Hi Aaron,

always nice hearing from you :)

As you mentioned the error happens when trying to parse the response into a JSON object. https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L179 and https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L61

The exception is handled in the catch block of onResponseReady: https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L248

This method cannot be overridden easily as it's not public and patching the .js file would be necessary.

The error message may be misleading in particular cases. It is most often caused by an incorrect redirect to a login or error page (which happens when the server has some kind of problem or is configured incorrectly and does not respond to the ajax request in a way the client side expects).

On the client side there is no way to find out what causes the redirect as it's handled transparently by the XMLHttpRequest.

To output the failed JSON string (e.g. an HTML document) the jq.evalJSON function can be overridden like this:

zk.afterLoad(function() {
    var origEvalJSON = jq.evalJSON;
    jq.evalJSON = function(jsonResponse) {
    try {
        origEvalJSON.apply(this, arguments);
        } catch (e) {
            //your code here to display the problematic text
            console.log('Error parsing JSON response:', e);
            console.log(jsonResponse);
            throw e;
        }
    };
});

Robert

Hi Aaron,

always nice hearing from you :)

As you mentioned the error happens when trying to parse the response into a JSON object. https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L179 and https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L61

The exception is handled in the catch block of onResponseReady: https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L248

This method cannot be overridden easily as it's not public and patching the .js file would be necessary.

The error message may be misleading in particular cases. It is most often caused by an incorrect redirect to a login or error page (which happens when the server has some kind of problem or is configured incorrectly and does not respond to the ajax request in a way the client side expects).

On the client side there is no way to find out what causes the redirect as it's handled transparently by the XMLHttpRequest.

To output the failed JSON string (e.g. an HTML document) the jq.evalJSON function can be overridden like this:

zk.afterLoad(function() {
    var origEvalJSON = jq.evalJSON;
    jq.evalJSON = function(jsonResponse) {
    try {
        return origEvalJSON.apply(this, arguments);
        } catch (e) {
            //your code here to display the problematic text
            console.log('Error parsing JSON response:', e);
            console.log(jsonResponse);
            throw e;
        }
    };
});

Robert

Hi Aaron,

always nice hearing from you :)

As you mentioned the error happens when trying to parse the response into a JSON object. https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L179 and https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L61

The exception is handled in the catch block of onResponseReady: https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L248

This method cannot be overridden easily as it's not public and patching the .js file would be necessary.

The error message may be misleading in particular cases. It is most often caused by an incorrect redirect to a login or error page (which happens when the server has some kind of problem or is configured incorrectly and does not respond to the ajax request in a way the client side expects).

On the client side there is no way to find out what causes the redirect as it's handled transparently by the XMLHttpRequest.

To output the failed JSON string (e.g. an HTML document) the jq.evalJSON function can be overridden like this:

zk.afterLoad(function() {
    var origEvalJSON = jq.evalJSON;
    jq.evalJSON = function(jsonResponse) {
     try {
         return origEvalJSON.apply(this, arguments);
        } catch (e) {
            //your code here to display the problematic text
            console.log('Error parsing JSON response:', e);
            console.log(jsonResponse);
            throw e;
        }
    };
});

Robert

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More