1
在離子中,我在嘗試解析JSON數據時遇到此錯誤。JSON解析中的離子3錯誤
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"]}}]
類型Script代碼:
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());
}}
您是否使用'ionic serve'運行?這可能是一個CORS問題 –
@suraj是的我運行在火狐瀏覽器使用離子服務 – Sumi
@suraj你可以請建議如何解決CORS問題 – Sumi