在chrome开发工具中,我收到错误“XMLHttpRequest无法加载https://www.carcraft.atsbusinessandgames.com/xmls/carcraft_1-7-10Test.xml。请求的资源上没有'Access-Control-Allow-Origin'标头Origin'https://carcraft.atsbusinessandgames.com'因此不被允许访问。“访问控制 - 允许来源甚至在同一个域上
为什么当这些文件都在同一个域上时出现此错误?
如果您需要在这里是适用的代码: XML(页面将是空白点击右键,查看源代码): https://carcraft.atsbusinessandgames.com/xmls/carcraft_1-7-10Test.xml
HTML页面的部分就被放进:
<article>
<header>
</header>
<br />
<br />
<table id="ModsList">
<tr style="font-weight: bold;">
<td>Mod Name</td>
<td>Author(s)</td>
<td>Version</td>
<td>Date added/updated</td>
<td>Description</td>
</tr>
</table>
<script src="https://www.code.jquery.com/jquery-1.8.1.min.js"></script>
<script src="/test.js"></script>
</article>
这里是JavaScript/jQuery的:
$.ajax({
url: 'https://www.carcraft.atsbusinessandgames.com/xmls/carcraft_1-7-10Test.xml',
type: "Get",
dataType: 'xml',
success: function (result) {
$(result).find('Module').each(function() {
var name = $(this).attr("name");
var url = $(this).find('url').text();
var authors = $(this).find('authors').text();
var version = $(this).find('version').text();
var date = $(this).find('date').text();
var description = $(this).find('description').text();
$("#ModsList").append("<tr>" + "<td>" + "<a href=" + url + ">" + name + "</a>" + "</td>" + "<td>" + authors + "</td>" + "<td>" + version + "</td>" + "<td>" + date + "</td>" + "<td>" + description + "</td>" + "</tr>");
});
},
failure: function() {
alert("Notify the site owner that the xml file is unreadable.");
}
});
哇,我觉得这么失去理智。谢谢!定时器允许我也将标记为接受。 – carstorm