Home  >  Article  >  Web Front-end  >  What to do if jQuery undefined error occurs in web script

What to do if jQuery undefined error occurs in web script

coldplay.xixi
coldplay.xixiOriginal
2020-11-26 10:18:274119browse

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代码
})

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>

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!

Statement:
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