Encapsulate a jsonp

MK Mack 2021-09-15 09:45:14

You may encounter more than one in development JSONP The requested callback function name is the same , This is where you need to encapsulate one JSONP, Here is a simple implementation :

function jsonp(url, jsonpCallback, success) {
let script = document.createElement('script')
script.src = url
script.async = true
script.type = 'text/javascript'
window[jsonpCallback] = function(data) {
success && success(data)
jsonp('http://xxx', 'callback', function(value) {
 Copy code 
Please bring the original link to reprint ,thank
Similar articles