Reputation: 3414
I have a problem about including javascript files to html.
I have an index.html which runs index.js
<script src="index.js" type="text/javascript"></script>
I also have viewer.html under view directory. And It has view.js
<script src="view.js" type="text/javascript"></script>
In index.js there is a get request to view.html when a button clicked in index.html
function viewReport(){
$.get('view/view.html', function(data) {
$('#filediv').html(data);
});
}
When I run localhost/view/view.html
it works fine. But when I click the button and make get request, It give me that error. Seems like it tries to find view.js in root directory.
http://localhost/view.js 404 (Not Found)
How can I solve this problem without copy/move view.js to root directory?
Upvotes: 2
Views: 650
Reputation: 1560
try adding a preceding slash, and closing your url string.
function viewReport(){
$.get('/view/view.html', function(data) {
$('#filediv').html(data);
});
}
Upvotes: 1