Margareth Didyk
Margareth Didyk

Reputation: 87

JQuery AJAX call: 304 respose produces an error

I have a script on localhost that sends a GET request to the same domain. It results in 304 response, which apparently JQuery treats as an error.

$(document).ready(function(){
    $.ajax({
        type: 'GET',
        url: 'http://localhost/file.js',
        error: function(e) {
            console.log('error: ' + e.responseText); // I see this message in console
        },
        success: function(e) {
            console.log('success: ' + e.responseText); // I don't see this message in console
        }
    });
});

1) Why do I get a 304 response? 2) How can I modify the code so that the success function gets called? (instead of error function)

Upvotes: 0

Views: 507

Answers (2)

labago
labago

Reputation: 1346

My guess is the error stems from you receiving a .js file, jQuery is expecting json

Upvotes: 1

imvain2
imvain2

Reputation: 15847

if you are loading a js file, add dataType: "script" to your ajax to force it expect js

Upvotes: 0

Related Questions