From 50179d52a2d0b9cb910eb47c8a1b0947459d26bc Mon Sep 17 00:00:00 2001 From: sourcebits-robertbiggs Date: Wed, 12 Aug 2015 16:20:33 -0700 Subject: [PATCH] Updated to 4.0.1 Added type information for timeout capability added to Fetch API. --- chocolatechipjs/chocolatechipjs-tests.ts | 25 ++++++++++++++++++++++++ chocolatechipjs/chocolatechipjs.d.ts | 19 +++++++++--------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/chocolatechipjs/chocolatechipjs-tests.ts b/chocolatechipjs/chocolatechipjs-tests.ts index cfb2ce854..647695909 100644 --- a/chocolatechipjs/chocolatechipjs-tests.ts +++ b/chocolatechipjs/chocolatechipjs-tests.ts @@ -341,6 +341,31 @@ function(data: any) { error.reject(); }); +// Timeout: +var formData2 = $.serialize($('form')[0]); +fetch('../controllers/php-post.php', { + method: 'post', + headers: { + "Content-type": "application/x-www-form-urlencoded; charset=UTF-8" + }, + body: formData, + // Set timeout: + timeout: 10000 +}) + .then($.json) + .then(function (data: any): any { + if (data.email_check == "valid") { + $("#message_ajax").html("
" + data.email + " is a valid e-mail address. Thank you, " + data.name + ".
"); + $("#message_ajax").append('

' + data.msg + '

'); + } else { + $("#message_ajax").html("
Sorry " + data.name + ", " + data.email + " is NOT a valid e-mail address. Try again.
"); + } + }) + // Catch timeout: + .catch(function(error) { + console.log(error); + }); + // $.jsonp: $.jsonp('https://api.github.com/users/rbiggs/repos?name=chipper', {timeout: 10000}) .then($.json) diff --git a/chocolatechipjs/chocolatechipjs.d.ts b/chocolatechipjs/chocolatechipjs.d.ts index 9a1b4c849..91f8f6654 100644 --- a/chocolatechipjs/chocolatechipjs.d.ts +++ b/chocolatechipjs/chocolatechipjs.d.ts @@ -1,4 +1,4 @@ -// Type definitions for chocolatechip v4.0.0 +// Type definitions for chocolatechip v4.0.1 // Project: https://github.com/chocolatechipui/ChocolateChipJS // Definitions by: Robert Biggs // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -1280,7 +1280,7 @@ declare type OpenEndedDictionary = Object; * Interface for fetch API. * * @param input A string representing a valid url. - * @param init An object literal of key value pairs to set method, headers, body, credentials or cache. + * @param init An object literal of key value pairs to set method, headers, body, credentials, cache or timeout. * @return Promise. */ @@ -1301,13 +1301,14 @@ interface fetch { include: string; }; cache?: { - default: string; - "no-store": string; - reload: string; - "no-cache": string; - "force-cache": string; - "only-if-cached": string; - } + default: string; + "no-store": string; + reload: string; + "no-cache": string; + "force-cache": string; + "only-if-cached": string; + }; + timeout?: number; }): Promise; }