ohad Posted June 20, 2020 Share Posted June 20, 2020 Hi All I have a site which is built from 3 folders: folder1 frolder2 frolder3 folder1 is the "master" folder. Means, In it I have the login page, connecxtion to DB elements, and header, footer and bootstrap treeview sidebar which I want to use in all the pages of the site. folders 2 and 3 each store all pages concern a specific vertical. The sidebar, which is located at folde1 retrive the content from database using AJAX, and Ive overloaded some of the original css by using custom css. here is psrt of the sidebar code: <link href="custom.css" type="text/css" rel="stylesheet" madia="all"/> <script type="text/javascript"> $(document).ready(function() { var treeData; $.ajax ({ type: "GET", url: "fill_sidebar.php", dataType: "json", When I load this sidebar to pages inside folder1 all works great The loading is done by this code: <script> $(document).ready(function () { $('#sidebar').load('sidebar.php'); }); </script> The loading for folder 2 is done by this code: <script> $(document).ready(function () { $('#sidebar').load('../folder2/sidebar.php'); }); </script>> When I try to load it to pages from other folder2 or 3 I get erroe message (in developer tools): folder2/custom.css net::ERR_ABORTED 404 (Not Found) jquery-3.5.1.js:10099 GET http://localhost/xxx/folder2/fill_sidebar.php 404 (Not Found) Of course, I i copy these files to folder2 all works fine, but I dont want to do that. I want to maintain only one file. My question is how to make these loads relative to the page I load? Quote Link to comment https://forums.phpfreaks.com/topic/310967-loading-files-from-other-locations/ Share on other sites More sharing options...
requinix Posted June 20, 2020 Share Posted June 20, 2020 Don't use relative paths like anything that starts with ../ Use absolute paths. If fill_sidebar.php is in folder1 then write /xxx/folder1/fill_sidebar.php. If it's somewhere else then write /xxx/somewhere-else/fill_sidebar.php. Quote Link to comment https://forums.phpfreaks.com/topic/310967-loading-files-from-other-locations/#findComment-1579039 Share on other sites More sharing options...
NotionCommotion Posted June 20, 2020 Share Posted June 20, 2020 While relative paths certainly work, they are often more trouble than they are worth. If you don't want to hard code them but still want to be flexible, consider using a PHP variable to define the base to relative path and use it in your URLs. Quote Link to comment https://forums.phpfreaks.com/topic/310967-loading-files-from-other-locations/#findComment-1579044 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.