node.js - Can i use and is secure to use AJAX in my Server Node? -


i use native ajax make calls inside node.js server.

is secure ?? can without problems ???

here's , example:

.... node  app.post('/postreceptor', function(req, res, next) {     var data1 = req.body['input1'];    var data2 = req.body['input2'];     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                  res.render('renderpage', {                  sendingdata: xhr.responsetext              });           }        }     };  }); 

this verify external page customer data sent client !

thanks !

doing ajax calls concept originated client side , in server don't have xmlhttprequest function available on node.js.

so make http request node.js, use http.request or use library request helping code without complexities, here example using request library:

var request = require('request'); var url = 'http://www.google.com';  request(url, function(error, response, body) {   if (!error && response.statuscode === 200) {     console.log(body);   } }); 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -