从返回res.json的expressJS路由检索结果的方法
在Heroku免费帐户(expressJS)url上运行的我的api端点 它显示来自expressJS路由的json响应。数据如下所示从返回res.json的expressJS路由检索结果的方法,json,heroku,polymer,iron-ajax,Json,Heroku,Polymer,Iron Ajax,在Heroku免费帐户(expressJS)url上运行的我的api端点 它显示来自expressJS路由的json响应。数据如下所示 [{"_id":"5938b81bd263a5144c9d7d17","title":"mlab first entry","__v":0}, {"_id":"5939efc7fac2b71aac4add11","title":"Second Entry","__v":0}, {"_id":"5939efd0fac2b71aac4add12","title"
[{"_id":"5938b81bd263a5144c9d7d17","title":"mlab first entry","__v":0},
{"_id":"5939efc7fac2b71aac4add11","title":"Second Entry","__v":0},
{"_id":"5939efd0fac2b71aac4add12","title":"Second Entry","__v":0}]
我从localhost()运行的代码:`
我需要格式化服务器res.json吗?还是使用res.format(对象)?
我很感激这里的任何帮助 当我试图从Codepen访问Heroku端点时,我收到一个CORS错误。这可能就是你的应用程序没有显示任何数据的原因。您可以检查DevTools中的网络面板吗?(控制台甚至可能会显示)这是有道理的。我必须弄清楚如何在ExpressJS route中做到这一点,以便它允许所有人进行通信。我很感激。你真是太好了,花时间调查一下。祝你周末愉快。
<!--
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="shared-styles.html">
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html">
<dom-module id="my-view1">
<template>
<iron-ajax
auto
url="https://shielded-caverns-24265.herokuapp.com/"
handle-as="json"
last-response="{{response}}">
</iron-ajax>
<<!--tried items={{response}} -->
<template is="dom-repeat" items="[[response.title]]">
<div>
<a href="{{item.title}}">     {{ item.title}}</a>
</div>
</template>
<!-- this code works and pull the data from https://reqres.in/api/users?page=2
<template is="dom-repeat" items="[[response.data]]">
<div>
<a href="{{item.first_name}} {{item.last_name}}"> {{item.first_name}}     {{ item.last_name}}</a>
</div>
</template>
-->
</template>
<script>
class MyView1 extends Polymer.Element {
static get is() { return 'my-view1'; }
}
window.customElements.define(MyView1.is, MyView1);
</script>
</dom-module>
router.get('/', function(req, res){
Comment.find(function(err, comments){
res.json(comments);
});
});