Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery in HTML with node.js as backend
    primarykey
    data
    text
    <p>I'm new to jQuery and node.js and this question has been bugging me for a couple of hours, I've searched stackoverflow and googled but couldn't find a solution.</p> <p>I'm testing this "hello world" example in jQuery and I tried running it with node.js, but it didn't work.</p> <p>Here is my code for node.js server:</p> <pre><code>var express = require('express'); var fs = require("fs"); var app = express.createServer(express.logger()); var path = require('path'); var indexText = fs.readFileSync("test.html"); app.use('/jquery', express.static(__dirname + '/jquery')); app.get('/', function(request, response) { response.send(indexText.toString()); }); var port = process.env.PORT || 8080; app.listen(port, function() { console.log("Listening on " + port); }); </code></pre> <p>So as you can see, I tried use express.static() to tell the node.js where jQuery lib is located. Here is the html for test.html:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;jQuery Hello World&lt;/title&gt; &lt;script type="text/javascript" src="/jquery/jquery-1.2.6.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $("#msgid").html("This is Hello World by JQuery"); }); &lt;/script&gt; This is Hello World by HTML &lt;div id="msgid"&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>It should print:</p> <p>This is Hello World by HTML This is Hello World by JQuery</p> <p>but it only prints hello from HTML</p> <p>The question might be stupid but I'm new to this so I require your help. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload