我是一個JQuery n00b。我試圖用$ .get()編寫一個非常簡單的代碼。 official documentation說
If a request with jQuery.get() returns an error code, it will fail silently unless the script has also called the global .ajaxError() method or. As of jQuery 1.5, the .error() method of the jqXHR object returned by jQuery.get() is also available for error handling.
所以,如果一切順利,我的成功回調函數將被調用。但是,如果請求失敗,我想獲取HTTP代碼:404,502等,併爲用戶制定有意義的錯誤消息。
但是,由於這是一個異步調用,我可以想象,我可能有幾個優秀的。 .ajaxError()如何知道它對應哪個請求?也許最好使用jQuery.get()返回的jqXHR對象的.error()方法?
有人可以prvode一個非常簡單的代碼示例?也許成功的程序調用警報(「頁面找到」)和故障例行檢查404並執行警報(「找不到網頁」)
更新:下面的頁面是非常有用的... http://api.jquery.com/jQuery.get/
+ 1That顯示了一個的n00b我,我不知道。我會嘗試一下並回復你。謝謝。 – Mawg 2011-02-19 23:28:48
順便說一句,我如何將CGI參數傳遞給URL。例如google.com?serach="pizza「 – Mawg 2011-02-20 00:54:23