任何人都可以看到以下最小示例的问题吗?我在标题中包括最新版本的jQuery。
jQuery(document).ready(function () { //<--- works normally
jQuery.ajax({ // <----- Error: "jQuery.ajax is not a function TypeError: jQuery.ajax is not a function"
url: "test.html",
context: document.body
}).done(function () {
jQuery(this).addClass("done");
});
...
错误:
jquery-3.3.1.slim.min.js:2 jQuery.Deferred exception: jQuery.ajax is not a function TypeError: jQuery.ajax is not a function
at HTMLDocument.<anonymous> (xxxx)
at l (https://code.jquery.com/jquery-3.3.1.slim.min.js:2:29567)
at c (https://code.jquery.com/jquery-3.3.1.slim.min.js:2:29869) undefined
您在项目中包含了jQuery Slim,它不支持jquery.ajax。使用jQuery的完整版。
如果您在jQuery中缺少函数,请确保您不是Slim版本(jquery-3.3.1.slim.min)。只需删除" .slim"。并且您的预期功能将存在(JQuery-3.3.1.min)。