Problems and solutions in JQuery 3.0 _jquery

Source: Internet
Author: User

The first phase of JQuery introduced 3.0 version, the changes are very large, if you want to use 3.0, we recommend a careful understanding of the new features, otherwise it will cause some minor problems, such as the following code.

Friends who are not familiar with the 3.0 ten new features of jquery can refer to this article.

 
 

Very simple, there is no problem at this point, the content can be displayed normally, but if there is an exception inside the $ (function () {...}), the problem is disturbing.

State after adding an exception

$ (function () {
throw new error (' Error ');
$ (' #container '). html (' hello ');

The page does not display the content is normal, but the console also does not display any error messages, obviously and our expectations are not the same

Because when using jquery 2 o'clock, in this case, the console can be prompted with the wrong

<script src= "Jquery-2.1.3.min.js" ></script>
<script>
$ (function () {
throw new Error ( ' A mistake ');
$ (' #container '). html (' hello ');
</script>

Solutions

Because jquery 3.0 officially supports promise, you can use the Promise form for. Ready () to throw an exception using fail

For example

$.ready.then (function () {
throw new error (' Error ');
$ (' #container '). html (' hello ');
Fail (function (error) {
throw error;
});

The console can then display the error message.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.