Reputation:
I was calling this function from javascript file. which was working perfect but now i want to call same function using Node js. please give me any alternate method. this function is use to insert data onclick event before.
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();
}
Upvotes: 0
Views: 55
Reputation: 707328
In node.js, you would generally use http.get()
from the http
module or request()
from the request
module. I find request()
is a bit easier to use:
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
}
});
There are a zillion other possible options for the request()
module described here.
Upvotes: 1