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.