Http请求编码对象
程序员文章站
2024-01-15 17:43:58
...
function encodeFormData(data) {
if(!data) {
return "";
}
var pairs = [];
for (const key in data) {
if (!data.hasOwnProperty(key)) continue;
if(typeof data[name] === 'function') continue;
var value = data[name].toString();
name = encodeURIComponent(name.replace("%20","+"))
value = encodeURIComponent(value.replace("%20","+"))
pairs.push(name + '=' + value)
return pairs.join("&")
}
}
将 { find: "pizza","radius": "1km"} 转化成 find=pizza&&radius=1km格式
上一篇: weak和strong
下一篇: c语言stdio.h源代码
推荐阅读