Ich benutze Restangular, um eine REST-API zu konsumieren, und es gibt mir immer diesen Fehler, obwohl ich die XHR-Anforderung erfolgreich auf der Entwicklerkonsole sehen kann.Warum gibt Restangular einen Fehler, obwohl die Anfrage erfolgreich ist
Fehler
{
"data":null,
"status":-1,
"config":{
"method":"GET",
"transformRequest":[null],
"transformResponse":[null],
"jsonpCallbackParam":"callback",
"headers":{"Accept":"application/json, text/plain, */*"},
"url":"http://localhost:8080/profile/v1/support/tickets"},
"statusText":""
}
Restangular API-Aufruf
angular.module('adf-widget-tickets-module-service',['restangular'])
.service('ticketCRUDService', function ($rootScope, Restangular, $http) {
Restangular.setBaseUrl('http://localhost:8080/profile/v1/support');
this.readTickets = function() {
Restangular.all('tickets').getList().then(function (response) {
var test = response.json;
console.log(test);
return test;
},function (err) {
console.error(JSON.stringify(err));
},function() {
console.log("loading......");
})
};
}
Könnten Sie mir bitte sagen, was mache ich falsch hier?
aktualisieren
Hier ist der Code für meine REST-Endpunkt
@GET
@Path("tickets")
@Produces("application/json")
public Response getAllTickets(){
ArrayList<Ticket> allTickets = new ArrayList<>();
try {
allTickets = elasticAPI.getAllTickets();
} catch (UnknownHostException e) {
e.printStackTrace();
}
return Response.ok(gson.toJson(allTickets), MediaType.APPLICATION_JSON_TYPE).build();
}
Es ist weired. Wenn ich den Endpunkt mit einem REST-Client teste, gibt es den Antwortcode 200. Ich kann auch sehen, dass die Anfrage gestellt wird und eine Antwort von 200 auf der Entwicklerkonsole erhalten wird. Könnte das ein CORS-Problem sein? –