简体   繁体   中英

XAMPP/Localhost external Javascript File empty

I've set up a website with XAMPP, have working on some PHP things and now tried to include some Javascript functions. My index.php is in the htdocs folder. In that htdocsfolder, I have a JS folder with a scripts.js file. The file shows up in my Sources when inspecting the website in my browser, but it is completely empty.

I have the following line in the head of my index file:

<script src="js/scripts.js" type="text/javascript" ></script>

I found this question: resource files are coming up empty when hosted locally

People mention it might be an htaccess problem. I don't know anything about htaccess. There is currently no htaccess file in my htdocs folder.

Code in my scripts.js file:

alert("Hi!");

function toggle(element, show) {
    document.getElementById(element).style.display = show;
}

function toggleLogin() {
    toggle('registerWrapper', 'none');
    toggle('loginWrapper', 'block');
}

function toggleRegister() {
    toggle('loginWrapper', 'none');
    toggle('registerWrapper', 'block');
}

How can I solve this?

Try to give that file full permissions just to see if that is your issue. Then lower it if that is a case.

Also see if the file owner is as your xampp expects (or as other files are)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM