From 52678f3b877e2e619b589afcd0d6f9fcab9e2f08 Mon Sep 17 00:00:00 2001 From: Junle Li Date: Wed, 11 Jun 2014 01:13:40 +0800 Subject: [PATCH] Add specs for jqXHR object returned by $.ajax The tests are corresponding to the syntax listed in its website: http://api.jquery.com/jQuery.ajax/#jqXHR --- jquery/jquery-tests.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index 63c4cdeb5..61b15b20b 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -151,7 +151,38 @@ function test_ajax() { dataType: "script" }); - // treat $.ajax() as a promise (as of 1.8) + // Test the jqXHR object returned by $.ajax() as of 1.5 + // More details: http://api.jquery.com/jQuery.ajax/#jqXHR + + // done method + $.ajax({ + url: "test.js" + }).done((data, textStatus, jqXHR) => { + console.log(data, textStatus, jqXHR); + }); + + // fail method + $.ajax({ + url: "test.js" + }).fail((jqXHR, textStatus, errorThrown) => { + console.log(jqXHR, textStatus, errorThrown); + }); + + // always method with successful request + $.ajax({ + url: "test.js" + }).always((data, textStatus, jqXHR) => { + console.log(data, textStatus, jqXHR); + }); + + // always method with failed request + $.ajax({ + url: "test.js" + }).always((jqXHR, textStatus, errorThrown) => { + console.log(jqXHR, textStatus, errorThrown); + }); + + // then method (as of 1.8) $.ajax({ url: "test.js" }).then((data, textStatus, jqXHR) => {