2017-06-15 6 views
0

Restrictionを使用してREST APIを使用していますが、開発者コンソールでXHRリクエストが正常に実行されていることがわかりましても、リクエストが成功したにもかかわらず、restangularがエラーを返す理由

エラー

{ 
    "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......"); 
     }) 
    }; 
} 

あなたはここで私が間違って何をやっているを教えていただけますか?あなたのエンドポイントが-1ステータスコードを返している理由はここに

更新

は私の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(); 
} 

答えて

1

ためのコードですか?私は、問題は私のクライアント側のコードではなかったと推測したよう200299

/* 
* A response status code between 200 and 299 is considered a success status and will result in 
* the success callback being called. Any response status code outside of that range is 
* considered an error status and will result in the error callback being called. 
* Also, status codes less than -1 are normalized to zero. -1 usually means the request was 
* aborted, e.g. using a `config.timeout`. 
* Note that if the response is a redirect, XMLHttpRequest will transparently follow it, meaning 
* that the outcome (success or error) will be determined by the final response status code. 
*/ 

https://github.com/angular/angular.js/blob/master/src/ng/http.js#L457

+0

うわべです。 RESTクライアントでエンドポイントをテストすると、レスポンスコード200が返されます。また、デベロッパーコンソールで200件の応答を受け取ることができます。これはCORSの問題でしょうか? –

0

角度は唯一の間で解決します。 CORSのために要求がサーバーから拒否されたためです。 CORSサポートのための適切な応答ヘッダーを設定することで問題は解決されました。

関連する問題