0

I have code like the following for chat app using the socket.io

<htmL>
<head>
<title>Chat with socket.io and node.js</title>
<style>
#chat{
height:500px;
}
</style>
</head>
<body>
<div id="chat"></div>
<form id="send-message">
<input size="35" id="message"></input>
<input type="submit"></input>
</form>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="socket.io/socket.io.js"></script>
<script>

jQuery(function($){
var socket=io.connect();
var $messageForm=$('#send-message');
var $messageBox=$('#message');
var $chat=$('#chat');

$messageForm.submit(function(e){
e.preventDefault();
socket.emit('send message',$messageBox.val());
$messageBox.val('');
$messageBox.focus();
});

socket.on('new message',function(data){
$chat.append(data+"<br/>");
});

});
</script>
</body>
</html>

When i am running this it was working fine.

But when ever I change the jquery file with local sotred one it was not getting that file even it present there. Please solve me.

Code after modification

<script src="/jquery.min.js"></script>
<script src="socket.io/socket.io.js"></script>

How to include external js file here.

2
  • Its a problem with your path, please add the folder structure of your app. Where are these files present? Commented Mar 23, 2015 at 11:24
  • If I gave complete path it giving the error as: Not allowed to load local resources. This path was successfully runned in normal application. But it gives error regard of the socket program. Commented Mar 23, 2015 at 11:29

1 Answer 1

1

Server Side jQuery

Use NPM to install jQuery on the server side: https://www.npmjs.com/package/jquery

Command Line: npm install jquery

Code: var $ = require('jquery');

Simples. *chirp*

Client Side jQuery

Place your file in a folder named "public" and load the file from there

<script src="/public/jquery.min.js"></script>

Then on server side (I'm assuming you're using express?), do:

//For Reference Only...
var express = require('express')
var app = express();

app.use('/public', express.static(__dirname + '/public'));

Then any other static files you want to load will have to be placed within the public folder.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.