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)
我的猜测是错误是由您收到.js文件引起的,jQuery期望使用json
如果您正在加载js文件,则将dataType:“ script”添加到您的ajax中以强制其期望js
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.