English 中文(简体)
处理json的对策
原标题:handling json response asynchronously

Check the code

var server = http.createServer(function(req, res){
    var parsedUrl = require( url ).parse(req.url);
    var pathname = parsedUrl.pathname;
    pathname = pathname.replace( /get/ ,  );

    GPSData.find({}, function(err, data) {
        if(err)
            console.log(err, data, data.length); 
        res.writeHead(200, {
                "Content-Type": "application/json",
                "Access-Control-Allow-Origin": "*"
        });
        console.log( hello );
         res.end(data);
    });

});

如何从干 to获得json数据并作反应? 如果我从全球定位系统数据中移出第7.end(一些-json )号,那么,我可以看到我的网页浏览器,但如何从干b中显示数据?

如何如此仓促地处理所有这些问题?

最佳回答

Ok I发现,在发出回击反应之前,我需要强化我的数据。

var body = JSON.stringify(data);
res.end(body);
问题回答

如果浏览器显示“没有这一网页”,那么你要么在奥塞莱收到一些错误信息,要么简单地缺失server.listen(<port_ number>





相关问题
How to make Sequelize use singular table names

I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.

What is Node.js? [closed]

I don t fully get what Node.js is all about. Maybe it s because I am mainly a web based business application developer. What is it and what is the use of it? My understanding so far is that: The ...

Clientside going serverside with node.js

I`ve been looking for a serverside language for some time, and python got my attention somewhat. But as I already know and love javascript, I now want learn to code on the server with js and node.js. ...

Can I use jQuery with Node.js?

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?

How do I escape a string for a shell command in node?

In nodejs, the only way to execute external commands is via sys.exec(cmd). I d like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a ...

热门标签