Reputation: 6547
I'm not sure why this is happening but i have a simple Ajax Code:
$.ajax({ url: "/javascript/testing.js"})
.done(function(data){ console.log(data) })
.fail(function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
});
.fail()
get's executed the status code is "OK". Also the data is present in responceText
to the actual legit data. Why is this happening?
Upvotes: 10
Views: 10740
Reputation: 10675
If you want to parse the javascript file, then the dataType should be script
:
$.ajax({ url: "/javascript/testing.js", dataType: "script" })
.done(function(data){ console.log(data) })
.fail(function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
});
If you are still getting a parserError
then there is a problem with your testing.js
file.
If you don't want to parse it and just retrieve it, then the dataType should be text
:
$.ajax({ url: "/javascript/testing.js", dataType: "text" })
Upvotes: 13