From 53a65fd0bebc14bc1214b919535c023d94e2967d Mon Sep 17 00:00:00 2001 From: "wisdom.emenike" Date: Wed, 16 Oct 2019 20:27:41 +0100 Subject: [PATCH] NetBridge now accepts the 'header' and 'data' attribute as a function which returns an object of the header or data respectively. --- net-bridge.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/net-bridge.js b/net-bridge.js index 1069a03..a6f615b 100644 --- a/net-bridge.js +++ b/net-bridge.js @@ -3,7 +3,7 @@ * Description: NetBridge is used for making asynchronous network (ajax) calls on web applications. * Author: Wisdom Emenike * License: MIT - * Version: 1.2 + * Version: 1.3 * GitHub: https://github.com/iamwizzdom/net-bridge */ @@ -152,7 +152,7 @@ NetBridge = (function() { if (__tm !== null) clearTimeout(__tm); __tm = setTimeout(() => { send(request); - }, 100); + }, 500); return; } @@ -229,7 +229,7 @@ NetBridge = (function() { let _tm = setTimeout(() => { if (queue.length > 0) send(shift()); clearTimeout(_tm); - }, 100); + }, 500); }; if (isNumeric(request.timeout)) xhttp.timeout = parseInt(request.timeout); @@ -265,6 +265,8 @@ NetBridge = (function() { xhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + if (isFunction(request.headers)) request.headers = request.headers(); + if (isObject(request.headers)) { for (let x in request.headers) { if (request.headers.hasOwnProperty(x)) @@ -272,6 +274,8 @@ NetBridge = (function() { } } + if (isFunction(request.data)) request.data = request.data(); + xhttp.send((isBoolean(request.processData) && request.processData === false ? request.data : serialize(request.data))); @@ -291,4 +295,4 @@ NetBridge = (function() { return NetBridge; -}()); +}()); \ No newline at end of file