我有以下问题:
在我用于从PHP脚本检索数据的angular服务中,浏览器或angular从https切换到http。我的网站是通过HTTPS与HTS加载的,所以ajax请求被阻止为混合内容。
我为我的ajax服务编写了以下代码:
import { Injectable, } from '@angular/core';
import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class AjaxService {
private apiUrl: string = "https://example.com/myapi/myscript";
/**
* @param {Http} http HTTPService
*/
constructor(private http: Http) { }
/**
* @param {string} piece
*/
public getAllComponents(piece: string) {
console.debug("Get Components for Query: " + piece);
return this.http.get(this.apiUrl + "?compontent=" + piece).map((res: Response) => res.json());
}
[...]
}当我从主页https://example.com/Angular2Application调用页面并发出请求时,浏览器告诉我ajax请求因混合内容而被阻止,并告诉我他试图连接到http://example.com/myapi/myscript
发布于 2016-11-08 04:44:28
只需提供一个不带方案的url即可。例如:
private apiUrl: string = "//example.com/myapi/myscript";您的浏览器将与当前页面的方案相匹配,因此您可以避免出现混合内容问题。
发布于 2016-11-26 05:48:06
现在它起作用了。不知道为什么,但好吧。
Closed
https://stackoverflow.com/questions/40474086
复制相似问题