ionic3和角度HttpErrorResponse jsonp

时间:2018-08-18 10:13:21

标签: angular ionic-framework ionic3 jsonp

我有一个小问题,我不知道这是什么。我尝试使用ionic3和angular获取时间表机场数据json的数据信息。该代码工作正常,但是问题是当我运行测试代码并在chrome中显示控制台时,我得到了'HttpErrorResponse'。

See image

reddit-data.ts

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

@Injectable()
export class RedditDataProvider {

    private appId='common/v1/airport.json?';
    private baseUrl = 'https://XXXXXXXXXX.com/common/v1/airport.json?code=';

    constructor(public http: HttpClient) {
        console.log('Hello RedditData Provider');
    }


     city(city: string, country: string) {

         let url=this.baseUrl;
         url +=country;


         return this.http.jsonp(url,'callback');
     }

}

班级之家

import { Component } from '@angular/core';
import { NavController,ModalController  } from 'ionic-angular';
import { RedditDataProvider } from '../../providers/reddit-data/reddit-data';
import {AddPage} from '../../pages/add/add';
import { HttpClient} from '@angular/common/http';
import 'rxjs/add/operator/map';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html',

})
export class HomePage {

    public weatherList =[]

  constructor(public navCtrl: NavController ,public redditService: RedditDataProvider
  ,private modal:ModalController) {}



 addWeather(){

    const myModal = this.modal.create('AddPage');

    myModal.onDidDismiss( (data) => {
            if (data) {
            this.getWeather(data.city, data.country);
        }   

    });

        myModal.present();  

} 

      getWeather(city: string, country: string){
        this.redditService.city(city, country)

          .subscribe(data => {

            this.weatherList.push(data);  
               console.log(data);
          },err => console.log(err),()=> 
          console.log('get'))

      }
      viewForecast(cityWeather){

          console.log( 'view forcast');

      }

}

问题出在JSONP,状态错误“ JSONP错误”。我尝试其他服务器也遇到同样的问题。请任何解决方案。

0 个答案:

没有答案