我正在使用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问题吗? –