jquery missing object errors

In recent days appear to write front-end jquery debugging with IE is always "missing object" error, and finally find out why.


User said, "Missing Objects" 99% of the reason is the jquery reference path not visit. So I went to see my jquery reference path, the problem really lies here.

Conan said: only one truth. After all that is not possible to remove the rest, no matter how unreasonable, and that is the truth.


As we all know


A, js, html, images and other static resources springMVC years can not be accessed directly, as was Dispatcherservlet blocked. To access you need to configure the spring-mvc.xml in.


Two, jsp is not intercepted Dispatcherservlet, so users can access directly through the url to jsp file, in order to prevent users direct access to jsp, jsp took place under the WEB-INF, because the files in the web-inf are not directly accessible , accessible only via controller.


Says here, the reason most cited jquery also less than clear


A jquery library placed under WEB-INF


2 jquery library is not on the WEB-INF down , but there is no folder to configure a static resource access to it in the document in the spring-mvc.xml

<mvc:resources mapping="/js/**" location="/js/" />


3 Due to the relatively unfamiliar path, citing the wrong path


This is the error code:

<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<!DOCTYPE html>
<html>
<head>
    <script src="WEB-INF/jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("button").click(function(){
                $("p").toggle();
            })
        });
    </script>
</head>
<body>
<button type="button">切换</button>
<p>这是一个段落。</p>
<p>这是另一个段落。</p>

</body>
</html>

This is the wrong storage location:


The revised Code

<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<!DOCTYPE html>
<html>
<head>
    <script src="js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("button").click(function(){
                $("p").toggle();
            })
        });
    </script>
</head>
<body>
<button type="button">切换</button>
<p>这是一个段落。</p>
<p>这是另一个段落。</p>

</body>
</html>


The modified position jquery



At this point, the problem should be solved.

If wrong idea, please correct me.


Published 97 original articles · won praise 42 · views 120 000 +

Guess you like

Origin blog.csdn.net/LVGAOYANH/article/details/78819233