0

我正在使用以下代码从 MongoDB 休息服务获取响应。但它给出了错误

Uncaught SyntaxError: Unexpected token :

我已经使用命令在 MongoDB 中启用了休息服务

mongod  --rest  --jsonp

以下是ajax调用的代码:

    $.ajax({
      type: 'GET',    
      url: "myDB/myCollection/",
      dataType: 'jsonp',
      jsonp: 'jsonp',
      crossDomain: true, 
      success:function(result){
        console.log(result);
      }
    });

这是休息服务返回的数据:

{
  "offset" : 0,
  "rows": [
    { "_id" : { "$oid" : "57173811e28098f50d3e065a" }, "name" : "abc" } ,
    { "_id" : { "$oid" : "57173821e28098f50d3e065c" }, "name" : "xyz" }
  ],
  "total_rows" : 2 ,
  "query" : {} ,
  "millis" : 0
}

请帮助我使用 ajax 调用从 MongoDB 休息服务获取数据。

4

1 回答 1

0

我错过了启用httpinterface。使用以下命令启用它

mongod --httpinterface

于 2016-04-20T11:46:45.703 回答