modified code to work on jQuery $.Deferred

modified code to work on jQuery $.Deferred instead of Promice object for
wider compatibility, like iOS 7.* and some other older devices.