function post(URL, PARAMS)
{
var temp = document.createElement("form");
temp.action = URL;
temp.method = "post";
temp.style.display = "none";
for (var x in PARAMS)
{
var opt = document.createElement("textarea");
opt.name = x;
opt.value = PARAMS[x];
// alert(opt.name)
temp.appendChild(opt);
}
document.body.appendChild(temp);
temp.submit();
return temp;
}
调用方法:
方式一:
post('../authorize.php', {loginType:'facebook',username:'userID'});
方式二:
var body = {
"loginType" : "facebook",
"username":'userID'
};
post('../authorize.php', body);
附:实现get提交(有待检验)
function get(URL, PARAMS)
{
var temp = document.createElement("form");
temp.method = "get";
temp.style.display = "none";
var data = "?";
for (var x in PARAMS)
{
data += x + "=" + PARAMS[x] + "&";;
}
data = data.slice(0, data.length-1);
temp.action = URL + data;
document.body.appendChild(temp);
temp.submit();
return temp;
}
//get('../authorize.php', {loginType:'facebook',username:'userID'});