Skip to content

Commit 7fb44c5

Browse files
committed
release 1.1.1
1 parent 5ee6858 commit 7fb44c5

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

HISTORY.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
1.1.1 / 2017-6-10
2+
==================
3+
* Fix script error when script request error, thanks to @wheatma
4+
15
1.1.0 / 2017-6-7
26
==================
37
* Handle <script> error event, thanks to @michaelvial

build/fetch-jsonp.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
return 'jsonp_' + Date.now() + '_' + Math.ceil(Math.random() * 100000);
2424
}
2525

26-
// Known issue: Will throw 'Uncaught ReferenceError: callback_*** is not defined'
27-
// error if request timeout
2826
function clearFunction(functionName) {
2927
// IE8 throws an exception when you try to delete a property on window
3028
// http://stackoverflow.com/a/1824228/751089
@@ -37,7 +35,9 @@
3735

3836
function removeScript(scriptId) {
3937
var script = document.getElementById(scriptId);
40-
document.getElementsByTagName('head')[0].removeChild(script);
38+
if (script) {
39+
document.getElementsByTagName('head')[0].removeChild(script);
40+
}
4141
}
4242

4343
function fetchJsonp(_url) {
@@ -79,12 +79,6 @@
7979
jsonpScript.setAttribute('charset', options.charset);
8080
}
8181
jsonpScript.id = scriptId;
82-
jsonpScript.onerror = function () {
83-
reject(new Error('JSONP request to ' + _url + ' failed'));
84-
85-
clearFunction(callbackFunction);
86-
removeScript(scriptId);
87-
};
8882
document.getElementsByTagName('head')[0].appendChild(jsonpScript);
8983

9084
timeoutId = setTimeout(function () {
@@ -93,6 +87,15 @@
9387
clearFunction(callbackFunction);
9488
removeScript(scriptId);
9589
}, timeout);
90+
91+
// Caught if got 404/500
92+
jsonpScript.onerror = function () {
93+
reject(new Error('JSONP request to ' + _url + ' failed'));
94+
95+
clearFunction(callbackFunction);
96+
removeScript(scriptId);
97+
if (timeoutId) clearTimeout(timeoutId);
98+
};
9699
});
97100
}
98101

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"name": "fetch-jsonp",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Fetch JSONP like a boss using Fetch API",
55
"main": "build/fetch-jsonp.js",
66
"scripts": {
7+
"prepublish": "npm run lint && npm run clean && npm run build",
78
"test": "mocha --compilers js:babel/register --recursive --ui bdd --reporter spec",
89
"build": "babel src/ --modules umd --out-dir build",
910
"clean": "rm -rf build",

0 commit comments

Comments
 (0)