angular cors跨域资源共享设置 和formdata设置
来源:互联网 发布:德意志第三帝国 知乎 编辑:程序博客网 时间:2024/04/30 14:50
很简单,记下来方便找:
<pre name="code" class="javascript">.config(['$routeProvider', '$httpProvider', function ($routeProvider, $httpProvider) { // http://stackoverflow.com/questions/17289195/angularjs-post-data-to-external-rest-api $httpProvider.defaults.useXDomain = true;delete $httpProvider.defaults.headers.common['X-Requested-With']; // Use x-www-form-urlencoded Content-Type $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; $httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded'; // Override $http service's default transformRequest $httpProvider.defaults.transformRequest = [function(data) { /** * The workhorse; converts an object to x-www-form-urlencoded serialization. * @param {Object} obj * @return {String} */ var param = function(obj) { var query = ''; var name, value, fullSubName, subName, subValue, innerObj, i; for(name in obj) { value = obj[name]; if(value instanceof Array) { for(i=0; i<value.length; ++i) { subValue = value[i]; fullSubName = name + '[' + i + ']'; innerObj = {}; innerObj[fullSubName] = subValue; query += param(innerObj) + '&'; } } else if(value instanceof Object) { for(subName in value) { subValue = value[subName]; if(subValue != null){ // fullSubName = name + '[' + subName + ']'; fullSubName = name + '.' + subName; // fullSubName = subName; innerObj = {}; innerObj[fullSubName] = subValue; query += param(innerObj) + '&'; } } } else if(value !== undefined ) //&& value !== null { query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&'; } } return query.length ? query.substr(0, query.length - 1) : query; }; return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data; }]; }]);
0 0
- angular cors跨域资源共享设置 和formdata设置
- 跨域资源共享CORS [django上面 的设置]
- Access-Control-Allow- 设置 跨域资源共享 CORS 详解
- 跨域资源共享(CORS)
- 跨域资源共享CORS
- CORS 跨域资源共享
- 跨域资源共享 CORS
- 跨域资源共享cors
- CORS跨域资源共享
- 跨域资源共享 CORS
- 跨域资源共享(CORS)
- 跨域资源共享 CORS 详解
- 跨域资源共享 CORS 详解
- 跨域资源共享 CORS 详解
- 跨域资源共享 CORS 详解
- 跨域资源共享 CORS 详解
- 跨域资源共享 CORS 详解
- 跨域资源共享 CORS 详解
- UI-axure-原型图
- ORACLE日期时间函数大全
- C#中的委托 一看即明
- uboot 分析之 start.s
- HDU 2955 Robberies
- angular cors跨域资源共享设置 和formdata设置
- 网络编程整理IP地址
- 情商高的表现
- Spring 3.2.* MVC通过Ajax获取JSON数据报406错误
- iOS7中UITableView问题以及UITableViewCell的层级关系
- 谈谈iOS Animation
- 最长回文子串
- 解决rhel系统ssh和terminal打开慢
- Evaluate Reverse Polish Notation