Created
September 25, 2014 12:46
-
-
Save kurtsson/083e352f33795f494ac0 to your computer and use it in GitHub Desktop.
Cors request with preflight using jquery and angular that works in ie, ff and webkit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RestClient | |
constructor: (@endpoint,@$scope) -> | |
populate: (callback) -> | |
@populated = false | |
@errored = false | |
@data = {} | |
jQuery.ajax( | |
url: @endpoint | |
xhrFields: | |
withCredentials: true | |
success: (d, status, jqXHR) => | |
Log.debug "Loaded data from #{@endpoint}: #{status}" | |
Log.debug d | |
@data = d | |
@populated = true | |
if callback? | |
callback(d) | |
@$scope.$apply() | |
error: (jqXHR, status, error) => | |
Log.error "Error loading data from #{@endpoint}: #{status}" | |
@errored = true | |
if callback? | |
callback("error") | |
@$scope.$apply() | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment