我必须通过http GET将amount
和name
数组从javascript传递到php脚本。
var amount=new Array();
amount = document.form_perk.elements["amount[]"];
var name = document.form_perk.elements["name[]"];
http.open('get', 'perks.php?+obj2url("amount", amount)&obj2url("name", name)');
http.onreadystatechange = insertReply;
http.send(null);
这是怎么做到的?
答案 0 :(得分:0)
http.open('get', 'perks.php?+obj2url("amount", amount)&obj2url("name", name)');
应该是:
http.open('get', 'perks.php?' + obj2url("amount", amount) + '&' + obj2url("name", name)');
原始邮件:
使用此功能(从here修改):
function EncodeQueryData(arr_data, str_prepend) {
str_prepend = str_prepend || "";
var ret = [];
for (var d in arr_data)
ret.push(encodeURIComponent(str_prepend + d) + "=" + encodeURIComponent(arr_data[d]));
return ret.join("&");
}
var base_url = "perks.php";
var query_string = EncodeQueryData(amount, "amount") + '&' + EncodeQueryData(name, "name");
window.location = base_url + '?' + query_string;
这应该给你举例如下:
perks.php?amount0=10&amount1=27&name0=john&name1=sally
。