【发布时间】:2015-11-09 02:22:33
【问题描述】:
我遇到的问题是我的图表(使用 AJAX - POST - PHP)没有出现在 Amazon 上
http://cdpmotest.s3-website.eu-central-1.amazonaws.com/
它说(错误的方法 405 错误)
这是我的 CORS 配置:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
这是我的脚本:
<script>
$(document).ready(function(){
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
$.ajax({
url: 'graph-data.php',
type: 'POST',
dataType: 'json',
success: function(data) {
var array1 = data.map(function(item) {
return parseInt(item[1], 10);
});
var array2 = data.map(function(item) {
return parseInt(item[2], 10);
});
createGraph(array1, array2);
}
});//end AJAX request
function createGraph(array1, array2) {
var ctx = document.getElementById("chart-area1").getContext("2d");
var barChartData = {
labels : ["Land Acquisition","Design Concept","Permits and Licensing","Tendering","Elec.+Water Requests","Construction Start","Construction Finish","Site Handover"],
datasets : [
{
fillColor : "rgba(0,154,166,0.5)",
strokeColor : "rgba(0,154,166,0.8)",
highlightFill: "rgba(0,154,166,0.75)",
highlightStroke: "rgba(0,154,166,1)",
data : array1
},
{
fillColor : "rgba(77,79,83,0.5)",
strokeColor : "rgba(77,79,83,0.8)",
highlightFill : "rgba(77,79,83,0.75)",
highlightStroke : "rgba(77,79,83,1)",
data : array2
}
]
}//end bar chart data
window.myBar = new Chart(ctx).Bar(barChartData, {
responsive : true
});
}//end createGraph
});
</script>
它在本地主机(WAMPServer)上工作正常
你能帮帮我吗?
【问题讨论】:
-
405 http 状态码是:"Request-Line 中指定的方法对于 Request-URI 标识的资源是不允许的。响应必须包含一个 Allow 标头,其中包含有效方法列表请求的资源。”(参见w3.org/Protocols/rfc2616/rfc2616-sec10.html)。您可以将请求中的允许标头设置为某些内容吗?现在似乎是空的,也许这就是问题所在。
-
我已将 CORS 设置为
* 其中 * 是允许所有标题的通配符
标签: php ajax json amazon-web-services amazon-s3