From 7643a269b2697e7be29f65fe920d53db55421c09 Mon Sep 17 00:00:00 2001 From: noxhj Date: Wed, 11 Jun 2014 13:01:26 +0200 Subject: [PATCH 1/3] Add responseJSON attribute to JQueryXHR --- jquery/jquery-tests.ts | 3 +++ jquery/jquery.d.ts | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index 81ddb3ae1..b0f5dfc9a 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -86,6 +86,9 @@ function test_ajax() { success: function (data) { $('.result').html(data); alert('Load was performed.'); + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('Load ailed. responseJSON=' + jqXHR.responseJSON); } }); var _super = jQuery.ajaxSettings.xhr; diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index 70a9532ab..bb5a73fd9 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -80,7 +80,7 @@ interface JQueryAjaxSettings { /** * A function to be called if the request fails. The function receives three arguments: The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery 1.5, the error setting can accept an array of functions. Each function will be called in turn. Note: This handler is not called for cross-domain script and cross-domain JSONP requests. This is an Ajax Event. */ - error? (jqXHR: JQueryXHR, textStatus: string, errorThrow: string): any; + error? (jqXHR: JQueryXHR, textStatus: string, errorThrown: string): any; /** * Whether to trigger global Ajax event handlers for this request. The default is true. Set to false to prevent the global handlers like ajaxStart or ajaxStop from being triggered. This can be used to control various Ajax Events. */ @@ -168,6 +168,10 @@ interface JQueryXHR extends XMLHttpRequest, JQueryPromise { */ overrideMimeType(mimeType: string): any; abort(statusText?: string): void; + /** + * Property containing the parsed response if the response Content-Type is json + */ + responseJSON: any; } /** From 1555e362532efa5e61acb5ef909b2c2d6d789f36 Mon Sep 17 00:00:00 2001 From: Nicholas Oxh Date: Wed, 11 Jun 2014 16:35:24 +0200 Subject: [PATCH 2/3] Update jquery-tests.ts Fix spelling... --- jquery/jquery-tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index b0f5dfc9a..85020c870 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -6,7 +6,7 @@ function test_add() { $('li').add('p').css('background-color', 'red'); $('li').add(document.getElementsByTagName('p')[0]) - .css('background-color', 'red'); + .css('background-coailor', 'red'); $('li').add('

new paragraph

') .css('background-color', 'red'); $("div").css("border", "2px solid red") @@ -88,7 +88,7 @@ function test_ajax() { alert('Load was performed.'); }, error: function (jqXHR, textStatus, errorThrown) { - alert('Load ailed. responseJSON=' + jqXHR.responseJSON); + alert('Load failed. responseJSON=' + jqXHR.responseJSON); } }); var _super = jQuery.ajaxSettings.xhr; From 73e8a6b08e4818490848216d49705d31daf157ee Mon Sep 17 00:00:00 2001 From: Nicholas Oxh Date: Thu, 12 Jun 2014 07:06:12 +0200 Subject: [PATCH 3/3] Update jquery.d.ts Make responseJSON optional, since it is only present on jqXHR if the Content-Type of the response is "application/json". Since responseJSON is an "output" parameter on jqXHR, I don't think it makes any functional difference, if it is marked as optional or not, but logically it probably makes more sense... --- jquery/jquery.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index bb5a73fd9..e6cba94d2 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -171,7 +171,7 @@ interface JQueryXHR extends XMLHttpRequest, JQueryPromise { /** * Property containing the parsed response if the response Content-Type is json */ - responseJSON: any; + responseJSON?: any; } /**