我需要long polling为聊天应用程序实现.我一直在寻找,但我只是在JavaScript使用中找到了如何实现它JQuery.我怎样才能使用native JavaScript和实现它node.js?你能指导我一些相关的文章或材料吗?
我在这里看过类似的问题,但没有一个与我的情况相符.在我的网站我有3个JavaScript文件:client.js,server.js,myModule.js.在client.js我创建一个名为的窗口变量windowVar,我添加了一些atrributes.在myModule.js,我添加一些其他属性并在那里使用它,我导出文件并要求它server.js.
client.js:
window.windowVar= {
func1: function(args) {
//some sode here
},
counter:0
};
Run Code Online (Sandbox Code Playgroud)
myModule.js :
module.exports={wVar:windowVar, addMessage ,getMessages, deleteMessage};
windowVar.serverCounter = 0;
windowVar.arr1=[];
Run Code Online (Sandbox Code Playgroud)
server.js:
var m= require('./myModule');
Run Code Online (Sandbox Code Playgroud)
在node.js中运行服务器时,我收到以下错误:
ReferenceError:窗口未在object处定义.
<anonymous>
据我所知,window是一个浏览器属性,但在这种情况下如何解决错误呢?任何帮助表示赞赏
我的学校项目中的一些要求要求将一些 AJAX 请求发送到服务器的 url :
http://localhost:8000/messages/:id
Run Code Online (Sandbox Code Playgroud)
我应该将 id 的值设置为唯一的数字。我知道这?意味着查询搜索,正如这里#提到的 ,但这意味着什么?如果我将 id 值设置为等于 123,它是如何显示的,像这样:
或像这样::http://localhost:8000/messages/:123http://localhost:8000/messages/123
我很感激任何帮助
在创建服务器时node.js,该函数有两个参数:request和response.使用这样的请求:url.parse(request.url);给出发送的请求的url部分,我的问题是:url_parts.pathname; 和url_parts.path;?之间有什么区别 ?
谢谢