转换form data时,采用的方法在ie8中堆栈溢出,怎么解决?

$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
var param = function(obj) {
  var query = '', 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];
        fullSubName = name + '.' + 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;
};
    $httpProvider.defaults.transformRequest = [function(data) {  
    return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
}];
阅读 1.7k
1 个回答
✓ 已被采纳新手上路,请多包涵

已解决这个问题,改写了这个方法,不再递归调用本身

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题