首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Nodejs Ajax调用

Nodejs Ajax调用
EN

Stack Overflow用户
提问于 2016-12-10 00:40:28
回答 1查看 48关注 0票数 0

我是从javascript文件调用这个函数的。它工作得很完美,但现在我想用Node调用相同的函数。请给我其他的方法。此函数用于之前插入数据onclick事件。

代码语言:javascript
运行
复制
function signup_validations_google(name_g,email_g,pass_g) 
{
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","http://localhost:8000/uri?name="+name+"&email="+email+"&pass="+pass, true);
xmlhttp.onreadystatechange=function(){
    if (xmlhttp.readyState==4 && xmlhttp.status==200){
        string=xmlhttp.responseText;
        alert("Registration successful");
    }
}
xmlhttp.send();

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-10 01:08:53

在node.js中,您通常使用来自http模块的http.get()或来自request模块的request()。我发现request()更容易使用:

代码语言:javascript
运行
复制
const request = require('request');
let query = {name, email, pass};

request({uri: "http://localhost:8000/uri", query: query}, function(err, msg, body) {
    if (err) {
        // error here
    } else {
        // response here
    }
});

request()模块在此描述还有无数其他可能的选项。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41070971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档