2015-11-06 137 views
0

我嘗試在我的SpringMVC項目中發送ajax請求。ajax請求中的錯誤

$.ajax({ 
    contentType : 'application/json; charset=utf-8', 
    type : 'get', 
    url : 'order/get/'+i, 
    dataType : 'json', 
    data : {}, 
    success : function(result) { 
     alert("Successfully!"); 
    }, 
    error : function(result, status, er) { 
     alert("error: "+result+" status: "+status+" er:"+er); 
    } 
}); 

@RequestMapping(value = "/order/get/{id}", method = RequestMethod.GET) 
public ResponseEntity<Order> getOrder(
     @PathVariable("id") long id) { 
    Order order = orderService.getOrderById(id); 
    if (order == null) { 
     new ResponseEntity<Order>(HttpStatus.NOT_FOUND); 
    } 
    return new ResponseEntity<Order>(order, HttpStatus.OK); 
} 

但我總是得到錯誤。 在'order'的控制器方法返回對象中,但ajax拋出'GET net :: ERR_CONNECTION_RESET'。 爲什麼?

+0

共享完整的錯誤消息,客戶端和服務器端 – sidgate

+0

@sidgate所有已知的錯誤'X-Requested-With' –

回答

0

問題是Order實體被序列化爲JSON並具有所有屬性,包括那些標記爲@ManyToOne的屬性。這個Json系列化過度了,反應非常巨大。實體類Order,必須指定@JsonIgnore這樣的註釋屬性。此錯誤消失後,答案正常處理。