【问题标题】:Ionic 4 Angular Getting response from API doesn't working. By postman I get correctIonic 4 Angular 从 API 获取响应不起作用。通过邮递员,我得到了正确的
【发布时间】:2019-06-14 05:26:41
【问题描述】:

离子 v4

物品控制器: enter image description here

DevTools 中的响应 -> 在“数据”中我总是从数据库中获取数据 - 在 Web 应用程序中一切正常 enter image description here

邮递员的回应:

enter image description here

谁能解释一下我的代码有什么不好?

离子信息: 离子:

离子(离子 CLI):4.8.0(C:\Users\Admin\AppData\Roaming\npm\node_modules\ionic) 离子框架:@ionic/angular 4.0.0-rc.1 @angular-devkit/build-angular:0.11.4 @angular-devkit/原理图:7.1.4 @角/cli:7.1.4 @ionic/angular-toolkit:1.2.2

科尔多瓦:

cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1) Cordova 平台:安卓 7.1.4 Cordova 插件:cordova-plugin-ionic-keyboard 2.1.3、cordova-plugin-ionic-webview 2.3.2(和其他 5 个插件)

系统:

NodeJS : v8.11.1 (C:\Program Files\nodejs\node.exe) npm:6.4.1 操作系统:Windows 10

编辑:@N 之后的新响应。塔西奇评论: enter image description here

EDIT2:更改 Content-Type application/json 后

获取item-front:enter image description here

获取项目后端:enter image description here

登录后台:enter image description here

【问题讨论】:

  • 在 devtools 的响应中,我们可以看到一个 html 代码而不是 json 数据

标签: angular api ionic-framework ionic4


【解决方案1】:

您正在请求

应用程序/x-www-form-urlencoded

所以,如果您希望您的响应是 JSON 更改标头 - 控制器中的内容类型。用

改变它

应用程序/json

【讨论】:

  • 谢谢,但这并不能解决问题。现在我得到 200 错误,没有来自数据库的数据。 - 根据您的建议,我添加了新图片
  • 但是你尝试了这个登录,在项目控制器中更改它,而不是在登录中。这也可能是不支持 json 响应的服务器端问题。您需要在此处设置 json 响应,然后使用 app/json 内容类型调用 api。
  • 登录和项目也是如此。我添加了项目的屏幕截图,并从后端的 getItem 以及 /login 添加了代码
  • 而且即使是镜头也没有到达后端,因为我没有在 intellij idea 的断点处停下来
猜你喜欢
  • 1970-01-01
  • 2018-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-21
  • 2020-08-31
相关资源
最近更新 更多