EDIT: This question has been substantially edited in response to comments.
I use window.onerror to catch syntax errors in my JS scripts. I made an Ajax call (unimportant in itself) which returned an empty response:
$.ajax({
url:"../php/ajax/outdated-ajax.php",
method:"POST",
data:{"getusers" : JSON.stringify(gMetaData)},
})
.done(function(response) { // response = ""
var incoming = JSON.parse(response);
...
I would have expected window.onerror to flag the fault in JSON.parse caused by the empty response, but I got the unhelpful "Script error", (perhaps implying some CORS issue), rather than the expected "Uncaught SyntaxError: Unexpected end of JSON input" or similar. I've tried putting in the fully qualified url but this makes no difference.
All my JS scripts and PHP functions are on the same domain. Could the "Script error" response be something to do with the error occurring within a promise?
Why this error and how can I avoid it?