支持自定义callback名字
parent
6f0b378c19
commit
6ce97228a7
|
@ -23,6 +23,7 @@ function jsonp(url, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var prefix = options.prefix || '__jp';
|
var prefix = options.prefix || '__jp';
|
||||||
var callback = options.callback || 'callback';
|
var callback = options.callback || 'callback';
|
||||||
|
var callbackName = options.callbackName;
|
||||||
var params = options.data || {};
|
var params = options.data || {};
|
||||||
var timeout = options.timeout ? options.timeout : 15000;
|
var timeout = options.timeout ? options.timeout : 15000;
|
||||||
var target = document.getElementsByTagName('script')[0] || document.head;
|
var target = document.getElementsByTagName('script')[0] || document.head;
|
||||||
|
@ -30,7 +31,7 @@ function jsonp(url, options) {
|
||||||
var timer = void 0;
|
var timer = void 0;
|
||||||
var promise = void 0;
|
var promise = void 0;
|
||||||
// Generate a unique id for the request.
|
// Generate a unique id for the request.
|
||||||
var id = prefix + count++;
|
var id = callbackName || prefix + count++;
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "simple-jsonp-promise",
|
"name": "simple-jsonp-promise",
|
||||||
"version": "1.0.8",
|
"version": "1.0.9",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -18,6 +18,7 @@ function jsonp(url, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
let prefix = options.prefix || '__jp';
|
let prefix = options.prefix || '__jp';
|
||||||
let callback = options.callback || 'callback';
|
let callback = options.callback || 'callback';
|
||||||
|
let callbackName = options.callbackName;
|
||||||
let params = options.data || {};
|
let params = options.data || {};
|
||||||
let timeout = options.timeout ? options.timeout : 15000;
|
let timeout = options.timeout ? options.timeout : 15000;
|
||||||
let target = document.getElementsByTagName('script')[0] || document.head;
|
let target = document.getElementsByTagName('script')[0] || document.head;
|
||||||
|
@ -25,7 +26,7 @@ function jsonp(url, options) {
|
||||||
let timer;
|
let timer;
|
||||||
let promise;
|
let promise;
|
||||||
// Generate a unique id for the request.
|
// Generate a unique id for the request.
|
||||||
let id = prefix + (count++);
|
let id = callbackName || (prefix + (count++));
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
||||||
|
@ -82,4 +83,4 @@ function jsonp(url, options) {
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default jsonp;
|
export default jsonp;
|
||||||
|
|
Loading…
Reference in New Issue