Can i use and is secure to use AJAX in my Server Node ??

24 views
Skip to first unread message

Angel Rodriguez

unread,
Jul 5, 2015, 10:19:14 AM7/5/15
to nod...@googlegroups.com

i would like to use native ajax to make some calls inside my node.js server.

Is this secure ?? Can i do it without problems ???

Here's and example:

.... NODE


app.post('/postReceptor', function(req, res, next) {

// DATA

        var data1 = req.body['input1'];

var data2 = req.body['input2'];

// AJAX

var xhr;

if (window.XMLHttpRequest) { // Mozilla, Safari, ...

 xhr = new XMLHttpRequest();

} else if (window.ActiveXObject) { // IE

 try {

   xhr = new ActiveXObject('Msxml2.XMLHTTP');

 } 

 catch (e) {

   try {

     xhr = new ActiveXObject('Microsoft.XMLHTTP');

   } 

   catch (e) {}

 }

}

xhr.open('GET', encodeURI('HTTP://WWW.WEBSITE.COM'), true);

xhr.send(null);

xhr.onreadystatechange = function() {


if(xhr.readyState === 4) { // done

   if(xhr.status === 200) { // complete

// > RENDERING RESULTS

res.render('renderPage', { 

 sendingData: xhr.responseText

});

 }

}

};

});

Thanks !

Ryan Schmidt

unread,
Jul 6, 2015, 12:04:23 AM7/6/15
to nod...@googlegroups.com

On Jul 5, 2015, at 9:13 AM, Angel Rodriguez wrote:

> i would like to use native ajax to make some calls inside my node.js server.
>
> Is this secure ?? Can i do it without problems ???
>
> Here's and example:
>
> .... NODE
>
>
>
> app.post('/postReceptor', function(req, res, next) {
>
> // DATA
>
> var data1 = req.body['input1'];
>
> var data2 = req.body['input2'];
>
> // AJAX
>
> var xhr;
>
> if (window.XMLHttpRequest) { // Mozilla, Safari, ...
>
> xhr = new XMLHttpRequest();

There's no such thing as "window" in Node. "window" is a concept used by web browsers.

Have you already investigated the facilities built into node for talking to other servers? Or the popular "request" module you can find on npm?

Reply all
Reply to author
Forward
0 new messages