我的代码的另一个问题。我正在尝试在成功请求的情况下附加函数,但它似乎不起作用。我的代码到目前为止:
const nbg = function() {
$.ajax({
url: "http://rmpc/json/notices.json",
method: "GET",
dataType: "json",
cache: false,
success: function (data) {
alert("WORKS");
}
});
};
然而,每当我尝试success: alert("WORKS")
时,它突然起作用。我非常困惑。有任何想法吗?谢谢
编辑:'rmpc'是我家网络上的本地Web服务器,我可以添加
这意味着请求不成功所以必须是一个错误。你需要抓住它以找出答案
const nbg = function () {
$.ajax({
url: "http://rmpc/json/notices.json",
method: "GET",
dataType: "json",
cache: false,
success: function (data) {
alert("WORKS");
},
error: function (xhr, error) {
console.debug(xhr);
console.debug(error);
},
});
};