From 6ce97228a7587c03cbce65c8f0f51112087c50d9 Mon Sep 17 00:00:00 2001 From: Ziqiang Li Date: Mon, 20 May 2019 18:24:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89ca?= =?UTF-8?q?llback=E5=90=8D=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/index.js | 3 ++- package.json | 2 +- src/index.js | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build/index.js b/build/index.js index 65ed030..9321804 100644 --- a/build/index.js +++ b/build/index.js @@ -23,6 +23,7 @@ function jsonp(url, options) { options = options || {}; var prefix = options.prefix || '__jp'; var callback = options.callback || 'callback'; + var callbackName = options.callbackName; var params = options.data || {}; var timeout = options.timeout ? options.timeout : 15000; var target = document.getElementsByTagName('script')[0] || document.head; @@ -30,7 +31,7 @@ function jsonp(url, options) { var timer = void 0; var promise = void 0; // Generate a unique id for the request. - var id = prefix + count++; + var id = callbackName || prefix + count++; function noop() {} diff --git a/package.json b/package.json index 0e315f7..068c1ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-jsonp-promise", - "version": "1.0.8", + "version": "1.0.9", "description": "", "main": "build/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 4096183..af0c461 100644 --- a/src/index.js +++ b/src/index.js @@ -18,6 +18,7 @@ function jsonp(url, options) { options = options || {}; let prefix = options.prefix || '__jp'; let callback = options.callback || 'callback'; + let callbackName = options.callbackName; let params = options.data || {}; let timeout = options.timeout ? options.timeout : 15000; let target = document.getElementsByTagName('script')[0] || document.head; @@ -25,7 +26,7 @@ function jsonp(url, options) { let timer; let promise; // Generate a unique id for the request. - let id = prefix + (count++); + let id = callbackName || (prefix + (count++)); function noop() {} @@ -82,4 +83,4 @@ function jsonp(url, options) { return promise; } -export default jsonp; \ No newline at end of file +export default jsonp;