Uncaught syntaxerror:unexpected Token <

Source: Internet
Author: User
Tags cas html header
Yesterday in debugging a project effect, the dead or dead out, with a chrome debugging, found a mistake: uncaught syntaxerror:unexpected token; After I navigate to the JSP file, I find the location is my HTML header file declaration: <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "http://www.w3c.org/TR/1999/REC-html401-19991224/ Loose.dtd "", I ordered the other page found no report this error, after a comparison of verification, to find the problem, the problems of the page application of the dynamic JS file: <script type= "Text/javascript" src= "${_" CONTEXTPATH}/${DETAILJS} "></script&gt, where the Datailjs did not find, (I was careless forgot to configure), led to the corresponding error, but I am not satisfied with this, want to know the root cause of the problem,

I use the Chrome Debug error page to view the JS code:

<script type= "Text/javascript" src= "/aabbcc/" ></script>
I think it is possible to refer to the JS source file path is not all caused, I did an experiment, I manually added the JSP page code as follows a JS reference;
<script type= "Text/javascript" src= "/aaa/" ></script>
Then chrome debugging, the error is as follows:
Get http://hello.cas.server:9080/aaa/404 (not Found)
, not as the title of the Uncaught syntaxerror:unexpected token, this is another I am very puzzling, after some thinking, I found a phenomenon, the page I quote the following JS:
<script type= "Text/javascript" src= "${_contextpath}/${detailjs1}" ></script>
<script type= "text /javascript "src="/aaa/"></script>

Build page:

<script type= "Text/javascript" src= "/boss_nqcp_manage/" ></script>
<script type= "Text/javascript" src= "/aaa/" ></script>

Chrome Error Results:

Get http://hello.cas.server:9080/aaa/404 (not Found)
index.do:20uncaught syntaxerror:unexpected Token <

We found that the problem is not, I was quoted after the/aaa/, but did first reported that it's wrong, it explains a problem, is that the JSP page will first handle the static reference page, which means that the address of the reference file is not a dynamic parameter of the page,

Then I used the real existence of the project path to do the test, test JS:

<script type= "Text/javascript" src= "/boss_nqcp_manage/resource/" ></script>
Build page:
<script type= "Text/javascript" src= "/boss_nqcp_manage/resource/" ></script>
The Chrome error is the same as the headline,
My conclusion is as follows: When JS refers to a file that is a folder under the project path, this error is reported.




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.