我正在使用Restangular來使用REST API,即使我可以在開發人員控制檯上看到XHR請求已成功創建,它總是會給我這個錯誤。儘管請求成功,但爲什麼會出現錯誤
錯誤
{
"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調用
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......");
})
};
}
你能告訴我我在做什麼錯在這裏?
更新
這裏是我的REST端點
@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();
}
這是我的。當我使用REST客戶端測試端點時,它會給出響應代碼200.我還可以看到正在發出的請求並在開發者控制檯上獲得200響應。這可能是一個CORS問題嗎? –