$.ajax is not a function
RojerChen.2018.10.17
今天發現先前改的程式 AJAX 功能失效,出現了這樣的錯誤
Uncaught TypeError: $.ajax is not a function ,查了一下,主因好像是先前更新了 bootstrap 之後,把 jquery 改成了 jquery-3.3.1.slim.min.js 這個了。
由於 slim 版本會拿掉一些功能,比方說 AJAX 功能,所以如果想要使用該功能,就改回使用 jquery-3.3.1.min.js 即可,詳細的內容可以參考 stackoverflow 這篇文章。
In the jquery.slim.js, the following function of code are removed:
- jQuery.fn.extend
- jquery.fn.load
- jquery.each // Attach a bunch of functions for handling common AJAX events
- jQuery.expr.filters.animated
- ajax settings like jQuery.ajaxSettings.xhr, jQuery.ajaxPrefilter, jQuery.ajaxSetup, jQuery.ajaxPrefilter, jQuery.ajaxTransport, jQuery.ajaxSetup
- xml parsing like jQuery.parseXML,
- animation effects like jQuery.easing, jQuery.Animation, jQuery.speed
Slim build
Sometimes you don’t need ajax, or you prefer to use one of the many standalone libraries that focus on ajax requests. And often it is simpler to use a combination of CSS and class manipulation for all your web animations. Along with the regular version of jQuery that includes the ajax and effects modules, we’ve released a “slim” version that excludes these modules. All in all, it excludes ajax, effects, and currently deprecated code. The size of jQuery is very rarely a load performance concern these days, but the slim build is about 6k gzipped bytes smaller than the regular version – 23.6k vs 30k.
0 意見:
張貼留言