Home > Web Front-end > JS Tutorial > body text

What to do if jQuery undefined error occurs in web script

coldplay.xixi
Release: 2020-11-30 11:28:40
Original
4120 people have browsed it

Solution to the jQuery undefined error in web scripts: Mount the jQuery file on your own website as a backup. If the CDN fails to load jQuery, use your own website to host jQuery.

What to do if jQuery undefined error occurs in web script

The operating environment of this tutorial: Windows 7 system, jquery version 3.1.1. This method is suitable for all brands of computers.

Solution to jQuery undefined error in web script:

The reason why JQuery is not defined is very simple, that is, when referencing JQuery’s js file, the order No, the jquery.js reference must be at the front, otherwise an error will occur.

Or put the js code using jQuery in the ready method

$(document).ready(function() {
    // 写jquery代码
})
Copy after login

Other reasons:

There is no problem with the jquery reference and path, but the chrome debugging source panel It was found that the jquery file was not loaded. This is a file or folder permissions issue, just modify the permissions.

There is a problem with the CDN that provides jQuery, causing jQuery to fail to load, or the browser times out when loading the jQuery file due to network problems, and a jQuery undefined error will occur.

Solution: Mount the jQuery file on your own website as a backup. If the CDN fails to load jQuery, use your own website to store and host jQuery. In this case, most users can still speed up access through CDN, and can avoid errors if there is a problem with the CDN.

<script src="https://cdn.staticfile.org/jquery/3.1.1/jquery.min.js"></script>
<script>
    window.jQuery || document.write(&#39;<script src="/js/jquery.min.js"><\/script>&#39;)
</script>
Copy after login

Related learning recommendations: js video tutorial

The above is the detailed content of What to do if jQuery undefined error occurs in web script. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template