Kick jsonp - fixes #2682
This commit is contained in:
parent
efdb563fa5
commit
716d1e1804
16 changed files with 8 additions and 362 deletions
|
|
@ -4,8 +4,6 @@ var buildPathname = require("../pathname/build")
|
|||
var hasOwn = require("../util/hasOwn")
|
||||
|
||||
module.exports = function($window, oncompletion) {
|
||||
var callbackCount = 0
|
||||
|
||||
function PromiseProxy(executor) {
|
||||
return new Promise(executor)
|
||||
}
|
||||
|
|
@ -197,23 +195,5 @@ module.exports = function($window, oncompletion) {
|
|||
else if (body instanceof $window.FormData || body instanceof $window.URLSearchParams) xhr.send(body)
|
||||
else xhr.send(JSON.stringify(body))
|
||||
}),
|
||||
jsonp: makeRequest(function(url, args, resolve, reject) {
|
||||
var callbackName = args.callbackName || "_mithril_" + Math.round(Math.random() * 1e16) + "_" + callbackCount++
|
||||
var script = $window.document.createElement("script")
|
||||
$window[callbackName] = function(data) {
|
||||
delete $window[callbackName]
|
||||
script.parentNode.removeChild(script)
|
||||
resolve(data)
|
||||
}
|
||||
script.onerror = function() {
|
||||
delete $window[callbackName]
|
||||
script.parentNode.removeChild(script)
|
||||
reject(new Error("JSONP request failed"))
|
||||
}
|
||||
script.src = url + (url.indexOf("?") < 0 ? "?" : "&") +
|
||||
encodeURIComponent(args.callbackKey || "callback") + "=" +
|
||||
encodeURIComponent(callbackName)
|
||||
$window.document.documentElement.appendChild(script)
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue