Reputation: 71
I'm frequently using .getScript to load in some dynamically generated javascript, and sometimes the data loaded in causes a parsererror, for instance when a string contained a quote which then ends the string too early in javascript, breaking the file.
Here's my code:
$.getScript(URL, function(data){
scriptCallback(data);
}).fail(function(jqxhr, settings, exception){
console.error('getScript fail! See below:');
console.error(jqxhr);
console.error(settings);
console.error(exception);
});
When a parsererror occurs, I get this output in the console:
getScript fail! See below:
An object with status 200 OK and responseText a great load of javascript
parsererror
SyntaxError: Unexpected identifier
at eval (<anonymous>)
at jquery-1.12.0.min.js:2
at Function.globalEval (jquery-1.12.0.min.js:2)
at text script (jquery-1.12.0.min.js:4)
at Wb (jquery-1.12.0.min.js:4)
at y (jquery-1.12.0.min.js:4)
at XMLHttpRequest.c (jquery-1.12.0.min.js:4)
However none of this actually helps me to figure out WHERE in the script file the error has occurred. I just want to be able to click into the contents of the script file it loaded and see where the error was, as you can in javascript that's on the page or in a loaded in file.
Is this just not possible?
Thanks.
Upvotes: 2
Views: 1091
Reputation: 53
Double-check, then triple-check the code that you are trying to load with getScript. In my case, I had a long SQL statement being passed into an AJAX post parameter, so for readability I had the statement split across several lines with concatenation. There was NO error from the IDE, but the getScript always returned parseError or SyntaxError... The fact that you cannot pinpoint the line of code with the problem is actually telling you that nothing was executed - the parseError means that nothing was run; the parsing of the target JavaScript failed before anything executes.
Upvotes: 1
Reputation: 1716
Normally the error happens in js file which name shows beside anonymous.
in your case it is eval
so click on it eval and its will take you to the line where error .
Upvotes: 0