0

Okay, I edited my question to show where I am at : I have a javascript test code :

$.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!"); }
});

And a PHP code running on the same server :

<?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);
?>

When I execute the PHP script I get the good XML page. But when I execute the JS, I still get "Failed!".

Could someone tell me what is wrong ? Thanks!

Jean-Michaël Celerier
  • 7,412
  • 3
  • 54
  • 75
  • It means your ajax call is failing every time. Where are you running this? – Codeman Oct 23 '13 at 21:13
  • maybe you'll find your answer here? [cross domain requests header](http://stackoverflow.com/questions/15477527/cross-domain-ajax-request) – ho.s Oct 23 '13 at 21:17
  • I just made a test web page with this script and nothing more except html headers. I am running it on localhost. (which is not www.boardgamegeek.com of course!) – Jean-Michaël Celerier Oct 23 '13 at 21:19
  • @ho.s : from your answer, it appears that "Assumption 2: YOU are NOT in control of the pages on server" implies that the only way to do what I want is to make a proxy ? really, there is no other way ? – Jean-Michaël Celerier Oct 23 '13 at 21:21
  • all I know (.. doesn't have to be 100% true as of latest updates or "magic" :-)) is that server has to be configured (send allow-origin headers) to allow access. I had that issue during a job where we had the same problem. so just setting "crossDomain: true" on client side is not enough – ho.s Oct 23 '13 at 21:29
  • Okay... So since I don't have access to the server, it won't work. But what is the point of making an open XML API then ? – Jean-Michaël Celerier Oct 23 '13 at 21:30
  • 1
    sorry I'm not really into this API .. did you try to find an answer/help on the website itself? the problem is mentioned i.e. [here](http://boardgamegeek.com/thread/99401/boardgamegeek-xml-api/page/47) .. – ho.s Oct 23 '13 at 21:38
  • Mhh okay from your link I will try to make JS call a PHP script with the url to parse, and then get the data back from the PHP script. Seems ugly, but anyway I'll post it as an answer if it works. – Jean-Michaël Celerier Oct 23 '13 at 21:42
  • `crossDomain: true,` doesn't actually do anything toward making a cross-domain request work, fyi. – Kevin B Oct 23 '13 at 21:53
  • Edited question with my current state – Jean-Michaël Celerier Oct 23 '13 at 22:01
  • 1
    it turns out (tested on localhost myself) that you get http 200 OK (thats what still causes "error" due to the known issue, but already get the beloved result `success: function(xhr) { console.log("Success");}, error: function(xhr) { console.log("Failed!");}, complete: function(xhr) {console.log(xhr.responseXML,xhr.responseText)}` – ho.s Oct 23 '13 at 23:24
  • Damn, okay XD So it is a bad idea to use error:, right ? – Jean-Michaël Celerier Oct 24 '13 at 09:46

0 Answers0