Jakolcz
Jakolcz

Reputation: 564

JavaScript file not loading - syntax error

I have this HTML code

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>MyPage</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="/scripts/FileFunctions.js"></script>
</head>
<body>
</body>
</html>

and this "FileFunctions.js" file

function addField(){
  $('form input:file').last().after($('<p><input type="file" name="files[]" id="file" /><br /></p>'));
};

but if I load the page, my file "FileFunctions.js" is not loaded... The javascript console says

Uncaught SyntaxError: Unexpected token < FileFunctions.js:1

but I can't find out what is wrong with these codes... Thanks for any ideas

Upvotes: 0

Views: 1561

Answers (2)

Jakolcz
Jakolcz

Reputation: 564

The problem was with wrong configuration in .htaccess. The apache returned my HTML page with info about non existing "scripts.php" file instead of "/scripts/FileFunctions.js".

Solution is simple, I've just added RewriteCond to .htaccess

RewriteCond %{SCRIPT_FILENAME} !scripts/(.*)$
RewriteRule ^([a-zA-Z0-9]+) index.php?page=$1 [QSA]

Upvotes: 2

jonosma
jonosma

Reputation: 339

I think there is an issue with your javascript. Try the code below

JS Fiddle: http://jsfiddle.net/jonocairns/Z2C9Y/1/

"use strict";
function addField() {
    $('form input:file').last().after('<p><input type="file" name="files[]" id="file" /><br /></p>');
};

Upvotes: 0

Related Questions