2014-04-14 24 views
1

我在Ember.js中爲來自Tornado服務器的搜索結果編寫了搜索操作。現在的問題是,當搜索沒有找到任何結果我提出用tornado.web.HTTPError(statuscode)錯誤:我怎樣才能得到在燼js行動龍捲風錯誤響應?

Server.py: 
========= 
      if not rows: 
      raise tornado.web.HTTPError(400) 

我試圖處理錯誤在我App.js文件中像這樣:

App.js: 
======== 
     search: function() { 
     // the current value of the text field 
     var query = this.get('query'); 
     data = $.ajax({ 
      dataType: "json", 
      url: "/search?query=" + query, 
      async: false}).error(function(response) { 
          alert(response.responseText); 
      }).responseJSON; 

在上面代碼當Tornado發生錯誤時,執行.error(response),但responseText爲空。

如何捕獲錯誤並重定向到錯誤頁面?

+0

是錯誤頁面的一個餘燼路由? – thecodejack

+0

它是餘燼路線 –

回答

2

問題不是來自EmberJS。其在Ajax Request。您正在請求JSON的data-type,但是您要發送的HTML內容(可能類似於<html><title>400: Bad Request</title><body>400: Bad Request</body></html>)在分析後返回空白。從AJAX請求中刪除數據類型爲JSON,或者在服務器中編寫您自己的自定義處理程序以在JSON模式下返回404錯誤。

class MyHandler(tornado.web.RequestHandler): 
    def get(self): 
     self.clear() 
     self.set_status(400) 
     self.finish("[]") //some JSON 
+0

謝謝...我想念,現在我改變我的code.its工作正常 –