Ionic 3 JSON 解析错误

问题描述 投票:0回答:2

在 Ionic 中,我在尝试解析 JSON 数据时收到此错误。

Error : Response with status: 0  for URL: null  

我需要以列表格式打印产品名称(姜黄粉)

JSON 响应是

[{"product_id":"40","sku":"HOS001","name":"Turmeric Powder","set":"9","type":"configurable","category_ids":["2","3"],"website_ids":["1"]},{"product_id":"41","sku":"HOS001-20 grms","name":"Turmeric Powder-20 grms","set":"9","type":"simple","category_ids":[],"website_ids":["1"]}}] 

输入脚本代码:

  getdata(){

  this.loading.present();
  this.httpProvider.getJsonData().subscribe(

  result => {
            console.log('getJsonData completed');

    this.newsData=result.data.result;
    console.log("Success : "+this.newsData);
  },
  err =>{
    console.error("Error : "+err);
  } ,
  () => {
    this.loading.dismiss();
    console.log('getData completed');
  }
);
}

Provider.ts

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

/*
Generated class for the HttpProvider provider.

 See https://angular.io/docs/ts/latest/guide/dependency-injection.html
 for more info on providers and Angular 2 DI.
 */

 @Injectable()
 export class HttpProvider {

 constructor(public http: Http) {
 console.log('Hello HttpProvider Provider');
 }

 getJsonData(){
  return this.http.get('http://happyos.in/prd.php').map(res => res.json());
 }}
javascript json parsing typescript ionic-framework
2个回答
0
投票

我通过添加 Google Chrome 扩展 Access-Control-Allow-Origin 找到了 CORS 问题的解决方案。但之前我们每次打开浏览器都必须启用它


0
投票

Diya A为什么选择Diya Agro Exports? 印度姜黄出口商:我们是印度姜黄粉和姜黄粉的主要出口商。 Haldi(姜黄)的好处:我们提供以其健康益处而闻名的姜黄产品,其中姜黄素含量为 1.5% 至 5.5%。 产品种类丰富:有各种等级、网眼尺寸和可定制选项的整姜黄、姜黄球和姜黄粉可供选择。 有竞争力的价格:我们在不影响质量的情况下为您提供最物有所值的服务。 已验证的供应商 在此输入图片描述

© www.soinside.com 2019 - 2024. All rights reserved.