作者kencool107 (臉都歪了)
看板Ajax
標題[問題] Ajax Post陣列的問題
時間Fri Jul 6 10:47:10 2012
今天網頁上有個表單
裡面有個幾個ckeckbox是複選用陣列存起來
<form name="formA" >
<input type="checkbox" name="paytype[]" value="1">
<input type="checkbox" name="paytype[]" value="2">
<input type="button" onclick="show();">
</form>
<script>
function show()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="type="+document.formA.paytype.value;//這行有問題
alert(url);
xmlHttp.onreadystatechange=stateChanged ;
xmlHttp.open("POST","getContend.php",true);
xmlhttp.setRequestHeader(
'Content-Type',
'application/x-www-form-urlencoded'
);
xmlHttp.send(url);
}
</script>
在想要取得 document.formA.type.value 的時候會錯誤
請問是哪裡有問題呢
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.251.55.25
※ 編輯: kencool107 來自: 60.251.55.25 (07/06 10:53)
1F:推 qwer820404:錯誤訊息是什麼?? 07/06 12:44
2F:推 kerash:不要拿有定義的文字當變數.. 07/06 12:50
我改成別的名字還是不行耶
我有alert( document.formA.paytype ) 他說undefined
※ 編輯: kencool107 來自: 60.251.55.25 (07/06 13:47)
3F:→ kerash:對javascript來說,只有paytype[] 這個名字,沒有 paytype 07/06 14:03
4F:→ kerash:如果傳過去 server 會變成 paytype 的陣列 07/06 14:04