SHARE
TWEET

Untitled

a guest Aug 18th, 2013 134 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @app.config(['$httpProvider', ($httpProvider) ->
  2.   $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'
  3.   $httpProvider.defaults.transformRequest = [(data) ->
  4.     param = (obj) ->
  5.       query = ''
  6.       for own name of obj
  7.         value = obj[name]
  8.         if value instanceof Array
  9.           for i in [0..value.length]
  10.             subValue = value[i]
  11.             fullSubName = "#{name}[#{i}]"
  12.             innerObj = {}
  13.             innerObj[fullSubName] = subValue
  14.             query += "#{param(innerObj)}&"
  15.         else if value instanceof Object
  16.           for own subName of value
  17.             subValue = value[subName]
  18.             fullSubName = "#{name}[#{subName}]"
  19.             innerObj = {}
  20.             innerObj[fullSubName] = subValue
  21.             query += "#{param(innerObj)}&"
  22.         else if value != undefined and value != null
  23.           query += "#{encodeURIComponent(name)}=#{encodeURIComponent(value)}&"
  24.       return (if query.length then query.substr(0, query.length - 1) else query)
  25.     if angular.isObject(data) and String(data) != '[object File]' then param(data) else data
  26.   ]
  27. ])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top