Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

html - How JavaScript load HTMP page with its own JavaScript file in different folder? Keep getting Error GET http://localhost:x/f.js 404 (Not Found) why?

In my JavaScript file that has name SPA.js, I am loading HTML page called MenuEditor.html with following location: wwwroot /HtmlTemp/MenuEditor.html Problem description

In MenuEditor.html I am trying to load JSmenuError.js that is in the same folder as the MenuEditor.html

I drag and drop the JSmenuError.js into MenuEditor.html

Error

I got Error GET http://localhost:xxx/file.js 404 (Not Found) in the chrome inspector.

404 (Not Found)

What is the issue with the path?

Please note that the JSmenu.js file that in the same folder as my main SPA.js works OK when I drag it into the MenuEditor.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It's a good idea to always use paths starting at the root of your webserver, for example /scripts/jsmenuerror.js. Different webservers and browsers have treated going up a directory (../) differently over the years. I haven't used ASP.NET Core, but there should also be a helper available like Url.Content or ResolveUrl you could use.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...