I am experiencing this same problem, and I have verified that the error "SyntaxError: JSON.parse: unexpected keyword" occurs before any callback handler is invoked.
My service complete handler includes the code:
precode
var responseTxt =(jqXHR.responseText);
console.log(responseTxt);
/code/pre
I am calling a search query on my REST service. When I call it with a valid search I get JSON back, but when no results are available it returns invalid JSON (returns the string "No Results").
My console log looks like the following:
precode
[13:17:40.407] GET http://appery.io/app/rest/tunnel?criteria=foo [HTTP/1.1 200 OK 655ms]
[13:17:41.031] [{ a valid JSON response containing objects that match the search string 'foo', printed by my complete handler}]
[13:17:55.000] GET http://appery.io/app/rest/tunnel?criteria=x [HTTP/1.1 200 OK 402ms]
[13:17:55.350] SyntaxError: JSON.parse: unexpected keyword @ http://appery.io/app/resources/preview/lib/jquery/jquery-1.8.2.js:514
/code/pre
I have no valid objects containing 'x' on my REST service, so the second response was "No Results" and the error occurred before my handler was invoked. The call stack confirms that this is the result of jQuery attempting to parse the JSON before it even returns from the $.ajax() call.
I tried using service_name.execute({}) wrapped in a try...catch instead of directly invoking the service, but for some unknown reason, the catch is never reached. I assume the actual $.ajax call is being handled via an event callback that is escaping my try...catch.
The way I normally handle this in my own web apps, when the REST service is unreliable and sometimes returns content that is not JSON-formatted, is to set the $.ajax dataType to 'text' and parse the results myself. I think that would be a good option for Appery -- allow the request type to be text -- although it would be tricky because JavaScript to parse the text would no longer be optional.
I still have no workaround for this. I am trying to figure out if I can configure or monkeypatch jQuery to behave.