I have a service that returns JSON data: http://api.drag2droid.shamanland.com/captcha?base64
I am trying to execute a simple AJAX request:
$.ajax({
type: "get",
url: "http://api.drag2droid.shamanland.com/captcha?base64",
dataType: "json",
success: function(data) {
$("body").html(data);
},
error: function(jqXHR, textStatus, errorThrown) {
$("body").html("ajax failed: " + textStatus + ", " + jqXHR.status + " " + errorThrown);
}
});
Result:
ajax failed: error, 0
But if I just paste this url into the address bar in my browser, I can see the json response.
Does anyone know of possible traps?
JSFiddle: http://jsfiddle.net/shomeser/n5TjL/
Edition:
In fact, I already configured my server side to allow all requests from any domain with any header, PHP code:
if ($_SERVER["REQUEST_METHOD"] == "OPTIONS") {
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Max-Age: 86400");
header("Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS");
if (isset($_SERVER["HTTP_ACCESS_CONTROL_REQUEST_HEADERS"])) {
header("Access-Control-Allow-Headers: {$_SERVER["HTTP_ACCESS_CONTROL_REQUEST_HEADERS"]}");
}
exit(0);
}
Edition:
On the Network tab of the Firebug plugin, I see that no content was found:

But the direct GET-reqeust from the browser shows the full content.
source
share