[問題] Ajax Post陣列的問題

看板Ajax作者 (臉都歪了)時間14年前 (2012/07/06 10:47), 編輯推噓2(202)
留言4則, 2人參與, 最新討論串1/1
今天網頁上有個表單 裡面有個幾個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)

07/06 12:44, , 1F
錯誤訊息是什麼??
07/06 12:44, 1F

07/06 12:50, , 2F
不要拿有定義的文字當變數..
07/06 12:50, 2F
我改成別的名字還是不行耶 我有alert( document.formA.paytype ) 他說undefined ※ 編輯: kencool107 來自: 60.251.55.25 (07/06 13:47)

07/06 14:03, , 3F
對javascript來說,只有paytype[] 這個名字,沒有 paytype
07/06 14:03, 3F

07/06 14:04, , 4F
如果傳過去 server 會變成 paytype 的陣列
07/06 14:04, 4F
文章代碼(AID): #1Fzb6nMr (Ajax)
文章代碼(AID): #1Fzb6nMr (Ajax)