如何发送来自node-express的AJAX请求?

在一个节点快递服务器,我得到一个巨大的IP地址arrays,我想在客户端的地图上可视化它。

由于数据集是巨大的,我认为最好是返回一个包含经度和纬度数组的json客户端。

事情是,从IP地址到地理位置,我需要发送ajax请求到api。 我可以在服务器上做这个吗?

$.ajax({ type: "GET", url: 'http://api/'+ip, dataType: "jsonp", success: function (res) { //do something; } }); 

谢谢。

在服务器端,你会有这样的东西:

 app.get('/api/:ip',function(req, res){ var ip = req.params.ip; geolocalizeIp(ip,function(latlng){ //you have to write this function res.json(latlng); }); }); 

客户可以使用它:

  $.ajax({ type: "GET", url: 'http://yourserver/api/'+ip, dataType: "json", success: function (res) { //res is yourArray, do stuff with it here; } });