//接口请求方式
window.request = {
header: {'Content-Type': 'application/x-www-form-urlencoded'},
type: 'post',
get:'get'
}
//接口格式转换
function transformRequest(data) {
var str = [];
for(var p in data){
console.log(typeof(data[p]));
if (typeof(data[p]) == 'object') {
var tmp = data[p];
// var arr = param[];
console.log(tmp);
$.each(tmp, function(k, v){
console.log(v);
if(typeof(v) == 'object'){
$.each(v, function(i, o){
str.push(encodeURIComponent(p+'['+k+']['+i+']') + "=" + encodeURIComponent(o));
// arr.join("&");
});
}else{
str.push(encodeURIComponent(p+'['+k+']') + "=" + encodeURIComponent(v));
}
});
// return ["param[0][width]=128¶m[0][height]=84¶m[0][width]=632¶m[0][height]=684"];
} else {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(data[p]));
}
}
console.log(str);
return str.join("&");
}
window.request = {
header: {'Content-Type': 'application/x-www-form-urlencoded'},
type: 'post',
get:'get'
}
//接口格式转换
function transformRequest(data) {
var str = [];
for(var p in data){
console.log(typeof(data[p]));
if (typeof(data[p]) == 'object') {
var tmp = data[p];
// var arr = param[];
console.log(tmp);
$.each(tmp, function(k, v){
console.log(v);
if(typeof(v) == 'object'){
$.each(v, function(i, o){
str.push(encodeURIComponent(p+'['+k+']['+i+']') + "=" + encodeURIComponent(o));
// arr.join("&");
});
}else{
str.push(encodeURIComponent(p+'['+k+']') + "=" + encodeURIComponent(v));
}
});
// return ["param[0][width]=128¶m[0][height]=84¶m[0][width]=632¶m[0][height]=684"];
} else {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(data[p]));
}
}
console.log(str);
return str.join("&");
}