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?
Many pages send AJAX requests to a server. Because this relies on the cooperation of the server and the network between the client and the server, you can expect these AJAX errors: Your JavaScript program receives an error response instead of data; Your program has to wait too long for the response.
The 500 Internal Server Error is a very general HTTP status code. It means something has gone wrong on the website and webserver is unable to specify what exactly, thus failing in fulfilling the request made by the client. Reload the web page. Clear your browser's cache.
Status code 0 means the requested url is not reachable.
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" })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With