ded / reqwest

browser asynchronous http requests
2.94k stars 341 forks source link

jsonp xhr no onerror callback ? #237

Open jun-lu opened 8 years ago

jun-lu commented 8 years ago

script.type = 'text/javascript'
        script.src = url
        script.async = true
        if (typeof script.onreadystatechange !== 'undefined' && !isIE10) {
            // need this for IE due to out-of-order onreadystatechange(), binding script
            // execution to an event listener gives us control over when the script
            // is executed. See http://jaubourg.net/2010/07/loading-script-as-onclick-handler-of.html
            script.htmlFor = script.id = '_reqwest_' + reqId
        }

        script.onload = script.onreadystatechange = function () {
            if ((script[readyState] && script[readyState] !== 'complete' && script[readyState] !== 'loaded') || loaded) {
                return false
            }
            script.onload = script.onreadystatechange = null
            script.onclick && script.onclick()
            // Call the user callback with the last value stored and clean up values and scripts.
            fn(lastValue)
            lastValue = undefined
            head.removeChild(script)
            loaded = 1
        }
jun-lu commented 8 years ago

is add script.onerror


script.onerror = function( error ){
            script.onerror = null;
            err( error )
            lastValue = undefined;
            head.removeChild(script)
            loaded = 1
        }