I created the simple server using nodejs and let it call html file which calls iquery. But it does not work with the browser showing the below two errors.
1. "Uncaught SyntaxError: Unexpected token <"
2. "Uncaught ReferenceError: $ is not defined at (index):13"
(Server side code)
var app = require('http').createServer(handler);
var fs = require('fs');
app.listen(1337);
function handler(req, res){
fs.readFile('index_test1.html', function(err, data){
if(err){
res.writeHead(500);
return res.end("Error");
}
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
res.end();
});
}
(index_test1.html code)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Demo1</title>
<script src="jquery-3.3.1.min.js"></script>
<style type="text/css"></STYLE>
</HEAD>
<BODY>
<p id="test"></p>
<script>
$(function(){
$('#test').text('Hello World!');
});
</script>
</BODY>
</HTML>
jquery-3.3.1.min.js is in the same folder where the server.js and index_test.html exist.
I hope someone help me out on this issue.
Thanks,