jQuery Promises throws ReferenceError

Eric Friedman's Avatar

Eric Friedman

18 May, 2016 05:11 PM

We have recently upgraded our JavaScript to use Promises with jQuery-2.2.3.

This works fine on a real iPad running iOS 9. However, it doesn’t work in Electric Mobile Studio 2012 v1.1.4. Instead, it throws the following error:
Uncaught ReferenceError: Promise is not defined

This version of jQuery loads without error.

  1. 1 Posted by Eric Friedman on 13 Jan, 2017 10:12 PM

    Eric Friedman's Avatar

    I've come upon a resolution for this issue. It not only works with Electric Plum emulator, but also with IE11 and older browsers that don't support Promise().

    Here's a couple of lines of JavaScript code that will automatically include the free bluebird library to add the necessary functionality to older JavaScript engines if necessary:

    // If Promise() function is not defined by current browser, load bluebird library to support it.
    if (typeof Promise !== "function") { jQuery.getScript("https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.3.4/bluebird.min.js")
        .fail(alert("Unable to load 'bluebird.min.js'."));
    }

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

16 Oct, 2021 02:38 PM
06 Oct, 2021 05:12 AM
20 Sep, 2021 04:14 PM
02 Aug, 2021 04:22 AM
29 Jul, 2021 07:22 AM