在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