I tried to make a GET call from a self written API in javascript (JQuery). I get an error but there is no message included.
Client code looks like this
$(document).ready(function () {
$.ajax({
type: "GET",
url: "APIURL...",
headers: {"Content-Type": "application/json;odata=verbose", "Accept": "application/json;odata=verbose", "crossDomain": "true", "credentials":"include"},
success: function (data) {
console.log(data);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus); //output: error
console.log(errorThrown); //output:
}
});
});
Also tested this with another url of a REST Test API https://jsonplaceholder.typicode.com/todos/1
. This works fine, it outputs the expected data in the success function. So I think the problem is somewhere in my own API.
I made the API with PHP and the Slim Framework. Code looks like this
$app->get ( '/test', function ($request, $response) {
$data["test"] = "data";
$json = json_encode ( $data );
$response->write ( $json );
return $response;
});
This is the called function from my jquery code. In the browser its output is as expected {"test":"data"}
The server where my API runs is reachable from the internet. Any solutions or suggestions?