jQuery、AJAX和;BoardGameGeek XML API

jQuery、AJAX和;BoardGameGeek XML API,jquery,ajax,xml,Jquery,Ajax,Xml,好的,我编辑了我的问题以显示我的位置: 我有一个javascript测试代码: $.ajax({ url: 'http://127.0.0.1/sgbd/web/bgg_talk.php', type: 'GET', dataType: 'text/xml', success: function() { alert("Success"); }, error: function() { alert("Failed!"); } }); 以及在同一服务器上运行的PHP代码: &l

好的,我编辑了我的问题以显示我的位置: 我有一个javascript测试代码:

$.ajax({
  url: 'http://127.0.0.1/sgbd/web/bgg_talk.php',
  type: 'GET',
  dataType: 'text/xml',
  success: function() { alert("Success"); },
  error: function() { alert("Failed!"); }
});
以及在同一服务器上运行的PHP代码:

<?php
$xmlStringContents = file_get_contents('http://www.boardgamegeek.com/xmlapi/search?search=Carcassonne');
header("Access-Control-Allow-Origin: *");
header("Content-Type: text/xml");
echo($xmlStringContents);
?>

当我执行PHP脚本时,我得到了良好的XML页面。 但是当我执行JS时,我仍然得到“Failed!”


有人能告诉我怎么了吗?谢谢

这意味着您的ajax调用每次都会失败。你在哪里运行这个?也许你会在这里找到你的答案?我刚刚用这个脚本制作了一个测试网页,除了html标题外,没有其他内容。我正在本地主机上运行它。(当然不是www.boardgamegeek.com!)对不起,我不是很喜欢这个API。。您是否试图在网站上找到答案/帮助?这里提到了这个问题,也就是说,(我自己在本地主机上测试过)您得到了http 200 OK(这就是由于已知问题仍然导致“错误”的原因,但是已经得到了令人喜爱的结果
success:function(xhr){console.log(“success”);},error:function(xhr){console.log(“Failed!”;},complete:function(xhr){console.log(“success”);},complete:function(xhr){console.log(xhr.responseXML,xhr.responseText)}