JS relative path correlation (for example: JS path depends on the path of the input JS file)

Source: Internet
Author: User

Problem Description:

A few days ago called the colleague's JS interface file, in his own HTML test page OK, on my side of the call when the problem occurs.

During the debug process, it is not possible to move the test HTML to another location, and it is OK to place it in the same hierarchical path as the original HTML test page.

Resolution process:

Very doubt Ah, with F12 debugging, in the invocation of JS, found that the Xmlhttp.status return status is 404, rely on, the original is not found file.

Look carefully, in JS see the following code: "var requesturl =". /servlet/ajaxservlet.jsp ";" The pit exploded,

Fuzzy remember that the reference path parsing in JS is dependent on the file path that references it, so it is changed to an absolute path:

"var requesturl ="/website project name/Intermediate folder/servlet/ajaxservlet.jsp ";". And then it's OK.

Knowledge Point: The relative path in CSS is based on the path of the CSS file, while the path in JS is based on the location of the file where this JS is imported.

Extended:

Relative path reference in CSS, JS: http://www.cnblogs.com/xuxiace/archive/2012/03/06/2381874.html

Summary of relative and absolute paths in the Java Web: http://www.cnblogs.com/jichunhu/archive/2013/01/31/2887042.html

JS relative path correlation (for example: JS path depends on the path of the input JS file)

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.