小编mis*_*der的帖子

GET Ajax 在响应中返回 html 代码而不是 json 对象

我有一个 ajax get 请求,如下所示。我正在使用 nodejs express 在 openshift 中向 server.js 发出 GET 请求。但是,我在响应方法中得到 html 内容而不是 json 对象。两个请求都是针对同一个域的。我使用的节点模块是 Moongojs、mongodb 和 bson。

$.ajax({
           type: "GET",
           url: "http://abc-favspot.rhcloud.com",
           contentType: "application/json",
           data: JSON.stringify(currLocation),
           dataType: "text",
           success: function(response){
           callback(response);
               },
            error: function( error ){
            console.log( "ERROR:", error );

                }
            });
Run Code Online (Sandbox Code Playgroud)

我的 server.js 文件有以下代码

self.routes['getData'] = function(req, res){
        console.log("gat method");            

    self.db.collection('location').find().toArray(function(err, names) {
       res.header("Content-Type:","application/json");
        console.log("success get");            
        res.send(names);
    });
  };
Run Code Online (Sandbox Code Playgroud)

jquery mongodb node.js openshift

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

jquery ×1

mongodb ×1

node.js ×1

openshift ×1