node.js服务器给出“这是一个字符串”。 (writeHeader,write(string),end)。
执行$ http请求时,我看到node.js服务器正在响应并发回信息。
在角我执行以下请求:
angular.module('phoneList').
component('phoneList', {
templateUrl: 'phone-list/phone-list.template.html',
controller: function PhoneListController($http) {
var self = this;
$http.get('http://127.0.0.1:8081/echo').then(function(response) {
self.data = response.data;
}, function(err) {
self.error = err;
self.status = response.status;
self.statusText = response.statusText;
});
}
});
响应
{ “数据”:NULL, “状态”: - 1, “配置”:{ “方法” :“GET”,“transformRequest”:[null],“transformResponse”:[null],“url”:“http://127.0.0.1:8081/echo”,“headers”:{“Accept”:“application/json, text/plain,/“}},”statusText“:”“}
我试着只从node.js或HTML文本发送JSON。没有不同。
'“状态”:-1'通常意味着你的后端不可用。可能是一个CORS'allow-origin'问题。控制台中有任何错误? – dex