-3

我必须通过 http GET 将数组从 javascript 传递到 php 脚本amountname

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);

这是怎么做到的?

4

1 回答 1

0

编辑:看来问题是这样的:

http.open('get', 'perks.php?+obj2url("amount", amount)&obj2url("name", name)'); 

应该:

http.open('get', 'perks.php?' + obj2url("amount", amount) + '&' + obj2url("name", name)');

原帖:

使用此功能(从此处修改):

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.

于 2012-10-22T14:28:02.560 回答