我有多个输入表单。一旦我提出了价值,我就应该通过jQuery Ajax传递它。它正在处理简单的html表单。但就多维形式而言,我失败了。
请帮助我在jQuery中获得价值。
我有html表格
<form action="index.php" method="POST">
<?php
for($a=0; $a<5; $a++) {
echo "<input type='text' name='IdentityID[]' placeholder='GB' onchange=\"getdetail(IdentityID[id]); return false;\"/>";
}
?>
</form>
JQuery ajax
function getdetail(IdentityID) {
alert(IdentityID); //I wan the value to appear here
$.ajax ({
type: "POST",
url: "getdetail.php",
data: { IdentityID: IdentityID},
success: function(data) {
$("#detail").html(data);
}
});
return false;
}
ReferenceError:未定义IdentityID
答案 0 :(得分:1)
在this.value
IdentityID[id]
onchange=\"getdetail(IdentityID[id])
答案 1 :(得分:0)
使用;
序列化整个表单var dataVal = $('form').serializeArray();
然后你的ajax请求变为:
$.ajax ({
type: "POST",
url: "getdetail.php",
data: dataVal,
success: function(data) {
$("#detail").html(data);
}
});
答案 2 :(得分:0)
<input type="text" onchange="getdetail(this.value)"/>
这就是答案。感谢@ guest271314