大佬教程收集整理的这篇文章主要介绍了typescript – CORS策略:在离子2中请求的资源上没有“Access-Control-Allow-Origin”标头,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我是混合开发的新手.我将这个Sample称为使用ionic2在listview中解析json.但是当我运行代码时,我只能看到浏览器中的空白屏幕.
下面我发布了代码.请检查 :
pages.ts:
import { Component } from '@angular/core'; import {http} from '@angular/http'; import { NavController } from 'ionic-angular'; import 'rxjs/add/operator/toPromise'; @Component({ SELEctor: 'page-home',templateUrl: 'pages.html' }) export class SlidingPage { public items:any; constructor(public navCtrl: NavController,public http: http) { this.http = http; this.http.get("http://api.randomuser.me/?results=10") .subscribe(data =>{ // console.log(data['_body']); // this.items=JSON.parse(data['_body']).results;//Bind data to items object this.items = data.json(); },error=>{ console.log(error);// Error getTing the data } ); } buttonClick(event){ console.log("button clicked"); console.log(event); } itemClicked(event,itemData){ console.log("item clicked"); console.log(event); console.log(itemData); } }
Pages.html:
<ion-header> <ion-navbar> <ion-title> List View </ion-title> </ion-navbar> </ion-header> <ion-content padding> <ion-list> <ion-item *ngFor="let item of items" (click)="itemClicked($event,item)"> <ion-avatar item-left> <img src="{{item.picture.thumbnail}}"> </ion-avatar> <h2>{{item.name.first | uppercase }}</h2> <h3>{{item.gender}}</h3> <ion-icon *ngIf="item.gender=='female'" name="woman" item-left></ion-icon> <ion-icon *ngIf="item.gender=='male'" name="man" item-left></ion-icon> <ion-icon name="heart" item-right></ion-icon> <button ion-button item-right color="danger" (click)="buttonClick($event)">Button</button> </ion-item> </ion-list> </ion-content>
我在Console中遇到了这个问题:
localhost/:1 XMLhttprequest cAnnot load http://api.randomuser.me/?results=10. Redirect from 'http://api.randomuser.me/?results=10' to 'https://api.randomuser.me/?results=10' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.
任何帮助表示赞赏.
@H_675_2@
>在Chrome浏览器中,设置 – >扩展程序 – >向下滚动并单击
获得更多扩展.
>搜索允许chrome web store中的origin allow control并将其添加到浏览器.
以上是大佬教程为你收集整理的typescript – CORS策略:在离子2中请求的资源上没有“Access-Control-Allow-Origin”标头全部内容,希望文章能够帮你解决typescript – CORS策略:在离子2中请求的资源上没有“Access-Control-Allow-Origin”标头所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。