Node.js 服务器给出“这是一个字符串”。 (写头,写(字符串),结束)。
当执行 $http 请求时,我看到 Node.js 服务器正在响应并发回信息。
在 Angular 中我执行以下请求:
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;
});
}
});
Response
{“数据”:null,“状态”:-1,“配置”:{“方法”:“GET”,“transformRequest”:[null],“transformResponse”:[null],“url”:“http://127.0.0.1:8081/echo http://127.0.0.1:8081/echo","headers":{"接受":"application/json,
文本/纯文本,/"}},"statusText":""}
我尝试只从 node.js 或 HTML 文本发送 JSON。没有不同。
请咨询$http 的官方 Angular 文档 https://docs.angularjs.org/api/ng/service/%24http#general-usage。它规定如下:
此外,小于 -1 的状态代码将归一化为零。 -1通常意味着请求被中止,例如使用config.timeout。
所以我猜你的后端有问题。也许查看开发人员控制台以检查请求是否到达您的服务器。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)