Discarding callback function on request end
authorAlexander Ebert <ebert@woltlab.com>
Sat, 17 Sep 2016 12:37:59 +0000 (14:37 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 17 Sep 2016 12:38:05 +0000 (14:38 +0200)
Fixes #2098

wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Jsonp.js

index 5e13bee8228306397f97de8d6972e4b37a3ed383..a71abef080287ce3860741dffac3b510db473050 100644 (file)
@@ -12,7 +12,7 @@ define(['Core'], function(Core) {
        /**
         * @exports     WoltLabSuite/Core/Ajax/Jsonp
         */
-       var AjaxJsonp = {
+       return {
                /**
                 * Issues a JSONP request.
                 * 
@@ -39,17 +39,19 @@ define(['Core'], function(Core) {
                        var callbackName = 'wcf_jsonp_' + Core.getUuid().replace(/-/g, '').substr(0, 8);
                        
                        var timeout = window.setTimeout(function() {
-                               window[callbackName] = function() {};
-                               
                                if (typeof failure === 'function') {
                                        failure();
                                }
+                               
+                               window[callbackName] = undefined;
                        }, (~~options.timeout || 10) * 1000);
                        
                        window[callbackName] = function() {
                                window.clearTimeout(timeout);
                                
                                success.apply(null, arguments);
+                               
+                               window[callbackName] = undefined;
                        };
                        
                        url += (url.indexOf('?') === -1) ? '?' : '&';
@@ -62,6 +64,4 @@ define(['Core'], function(Core) {
                        document.head.appendChild(script);
                }
        };
-       
-       return AjaxJsonp;
 });