Sunday 15 August 2010

node.js with readFile html but not loading/finding jquery file -


Let me tell my jquery file or any file to any node. Having trouble loading in Js read html file. I spent some time on this and found that the web based Google Hosted Library file works well, but I do not have a local file. I do not understand that, maybe I'm not directing it on the correct directory, but I'm not sure where I should say or direct it.

The directory contains these 3 files

  index.html jquery.min.js loadfile.js   

index.html Google The hosted jquery file has been commented just fine. But not locally.

  & lt ;! DOCTYPE html & gt; & Lt; Html lang = "en-us" & gt; & Lt; Top & gt; & Lt; Meta charset = "UTF-8" & gt; & Lt; Title & gt; & Lt; / Title & gt; & Lt; Script type = "text / javascript" src = "jquery.min.js" & gt; & Lt; / Script & gt; & Lt ;! - & lt; Script src = "// ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> - & gt; & Lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {warning ("test");}); & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; Hello! & Lt; / Body & gt; & Lt; / Html & gt;   

Here is the file that I load from the node I Loadfile.js

  var http = ('http'); Var url = requirement ('url'); Var FS = Requirement ('FS'); Server = http.createServer (function (request, response) {current_url = url.parse (. Request.url) .pathname; file_path = __dirname + current_url; var tmp = file_path.lastIndexOf ('.'); Var ext = file_path.substring (Ext. =); If (ext == 'js') response.writeHead (200, {' content-type ':' text / javascript '}); else if (ext ==' Type (200, {'content-type': 'text / html'}); if (current_url = 'CSS'); response.writeHead (200, {'content-type': 'text / CSS'}); = '/') {Fs.readFile ('index.html', 'utf8', function (errors, content) {response.end (content);})}} and {response.end ();}}); Server.listen (8000); Console.log ("Running in Local Host on Port 8000");   

I get this error Uncaught ReferenceError: $ $ is not defined on $ (document). Because it seems that I do not have to load jquery line.

Any help would be appreciated I can always use the Google hosted file, but it does not fit well with me thanks in advance!

You do not actually have file service , if current_url "/", your server can now send the file content of index.html to the client.

You have something like the following in your "Other" section:

  fs.readFile (file_path, 'utf8', function (errors, content) {response.end (material);});    

No comments:

Post a Comment