我需要在下表中使用JSON数据类型序列化输入和选定选项:
<form action="" method="post" id="formpiw" spellcheck="false" autocomplete="off">
<table id="tblpiw">
<tr id="trwil">
<td width="100">Area</td>
<td>
<select id="tdarea">
<option value="a" selected="selected">Area A</option>
<option value="b">Area B</option>
<option value="c">Area C</option>
</select>
</td>
</tr>
<tr>
<td>Name</td>
<td>
<input required type="text" id="name" />
</td>
</tr>
$.ajax({
url: "piw_proses.php",
type:"post",
data:$( ":input" ).serialize(),
dataType: 'json',
success:function(response){
我无法从选项中获取所选值! 输入被序列化。
答案 0 :(得分:1)
您错过了一个名称属性,要序列化它必须具有名称属性,请检查此documentation,此外您甚至可以使用:
var str = $( "form" ).serialize();
答案 1 :(得分:0)
您在选择和输入中错过了name
:
<select id="tdarea" name="tdarea">
<option value="a" selected="selected">Area A</option>
<option value="b">Area B</option>
<option value="c">Area C</option>
</select>
<input required type="text" id="name" name="name"/>