我已经申请了codeigniter
。我已将其上传到http://www.domain.com
。
但Chrome
不断传达信息......
Font from origin http://www.domain.com has been blocked from loading by Cross-Origin Resource Sharing policy. Origin 'http://domain.com' is therefore not allowed access
。
我将base_url
设置为config.php
http://www.domain.com
,但错误仍然存在。
当我将base_url
更改为http://domain.com
时,它会将错误视为......
Font from origin http://domain.com has been blocked from loading by Cross-Origin Resource Sharing policy. Origin 'http://www.domain.com' is therefore not allowed access
。
我已在web.config
中写下以下代码,但没有结果。
<staticContent>
<clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 IST" cacheControlMode="UseExpires" />
<remove fileExtension=".woff" /> <!-- In case IIS already has this mime type -->
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
<remove fileExtension=".eot" />
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
</staticContent>
我该怎么办?
更新
实际上错误来自域名。如果我在www.domain.com
config.php
为base_url()
时写http://domain.com
,则会出错。另一方面,如果我的domain.com
config.php
base_url()
http://www.domain.com
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/polymerfire/polymerfire.html">
<link rel="import" href="../bower_components/iron-image/iron-image.html">
<link rel="import" href="../bower_components/iron-list/iron-list.html">
<link rel="import" href="../bower_components/google-apis/google-apis.html">
<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html">
<link rel="import" href="shared-styles.html">
<dom-module id="doc-create">
<template>
<style include="shared-styles">
:host {
display: block;
padding: 10px;
}
</style>
<!--
<iron-ajax
auto
url="https://api.github.com/repos/firebase/polymerfire/issues"
handle-as="json"
params="{state: "closed", page: "1"}"
last-response="{{ajaxResponse}}"></iron-ajax> -->
<iron-ajax
auto
url="https://www.googleapis.com/drive/v3/about"
params = "{{ajaxParams}}"
handle-as="json"
with-credentials
last-response="{{ajaxResponse}}"></iron-ajax>
<div class="card">
<template is="dom-repeat" items="[[ajaxResponse]]">
<div class="horizontal-section">
<p>[[index]]: [[item.title]]</p>
</div>
</template>
</div>
<div class="card">
Response Data: [[ajaxResponse]]
Params: [[ajaxParams.fields]]
</div>
</template>
<script>
Polymer({
is: 'doc-create',
properties: {
fields: {
type: String,
value: 'user'
},
apikey: {
type: String,
value: 'ya29.CjBVA-xV9TJ9cS25hx9qJvEgD1w'
},
ajaxParams: {
type: String,
computed: 'processParams(fields, apikey)'
}
},
processParams: function(fields, apikey) {
return {
fields: fields,
key: apikey
};
}
// ,
// ready: function(){
// var request = api.url.get({
// shortUrl: 'oo.gl/fbsS'
// });
// request.execute(function(resp) {
// console.log(resp);
// });
// }
});
</script>
</dom-module>
{{1}}为{{1}},则表示错误。
答案 0 :(得分:1)
问题已解决。 (我不知道将来是否会出现另一个错误)
解决方案#1 (可能是最好的解决方案):
对于IIS 7 :(来源:Enable Cross-Origin Resource)
在web.config
文件中添加以下代码...
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
对于IIS 6:CORS on IIS6
对于Apache:CORS on Apache
对于其他平台:CORS support to server
解决方案#2 (我不知道它是否适用于所有服务器,但对我来说效果很好。)
来源:Codeigniter base url issue with www
在base_url
codeigniter
文件中配置config/config.php
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);