-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error trying to load javascript scripts by it src attribute #41
Comments
Recheck how you're referring to the js file from the template. Looks like the path is incorrect in |
Thanks for your response, how can I refer Javascript files? |
Please use the browser's console to inspect the exact contents of the If you are using PHP builtin server, I believe you need to return if (PHP_SAPI == 'cli-server') {
$url = parse_url($_SERVER['REQUEST_URI']);
$file = __DIR__ . $url['path'];
// check the file types, only serve standard files
if (preg_match('/\.(?:png|js|jpg|jpeg|gif|css)$/', $file)) {
// does the file exist? If so, return it
if (is_file($file))
return false;
// file does not exist. return a 404
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
printf('"%s" does not exist', $_SERVER['REQUEST_URI']);
return false;
}
} This is typically not an issue with any other server because you configure it to only call |
Make sure that See MDN |
This was an syntax error within the template. Closing this as solved. |
Hi!, I am new in PHP and I try to create an API with Slim, but when I try to load a javascript file inside a template by
<script src="dist/file.js"></script>
, it launch an error:Uncaught SyntaxError: Unexpected token <
.My project structure is:
My
public/index.php
code is:My
templates/index.html
code is:And my
public/dist/learning.js
code is:My
templates/index.html
andpublic/dist/learning.js
codes is to test, in my final project I will use Angular 5 to develop front-end.I checked this tutorial about Angular and Slim but it not works.
I tried with PHP 5.6 and PHP 7.2 but both launch the same error.
To run this project I use
php -S localhost:8080 -t public public/index.php
, because I have installed PHP without Apache or Nginx.I work on Windows 10.
Regards.
The text was updated successfully, but these errors were encountered: