繁体   English   中英

在客户端js和服务器node.js之间进行通信

[英]Communicating between client js and server node.js

我有一个正在尝试构建的单页应用程序,想知道如何在单击按钮以将数据返回到客户端时在节点中运行脚本。

我会用这样的东西吗?

function httpGet(theUrl)
{
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
    xmlHttp.send( null );
    return xmlHttp.responseText;
}

使用theUrl作为正在运行的快速实例的地址,该实例正在等待此请求以节点脚本的结果进行响应? 例如127.0.0.1:3030还是我选择用于监听的其他端口?

我要用完全错误的方式去做吗?

快速的问候世界示例可能是一个不错的起点。

https://expressjs.com/cn/starter/hello-world.html

var express = require('express')
var app = express()

app.get('/', function (req, res) {
  res.send('Hello World!')
})

app.listen(3000, function () {
  console.log('Example app listening on port 3000!')
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM