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;