Skip to content

Instantly share code, notes, and snippets.

@kurtsson
Created September 25, 2014 12:46
Show Gist options
  • Save kurtsson/083e352f33795f494ac0 to your computer and use it in GitHub Desktop.
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
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