支持自定义callback名字

pull/1/head
Ziqiang Li 2019-05-20 18:24:03 +08:00
parent 6f0b378c19
commit 6ce97228a7
3 changed files with 6 additions and 4 deletions

View File

@ -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() {}

View File

@ -1,6 +1,6 @@
{
"name": "simple-jsonp-promise",
"version": "1.0.8",
"version": "1.0.9",
"description": "",
"main": "build/index.js",
"scripts": {

View File

@ -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() {}