Php 使用jqueryajax传递表单元素的数组
我有一个表单,我需要将它传递到PHP页面 这是我的HTML部分Php 使用jqueryajax传递表单元素的数组,php,jquery,ajax,Php,Jquery,Ajax,我有一个表单,我需要将它传递到PHP页面 这是我的HTML部分 for ($j=0;$j<2;$j++) { ?> <tr><th><div class="col-xs-2"> <input class="form-control input-lg" name="Time[]" id="inputlg" type="text" value="" style="wi
for ($j=0;$j<2;$j++) {
?>
<tr><th><div class="col-xs-2">
<input class="form-control input-lg" name="Time[]" id="inputlg" type="text" value="" style="width:120px; height:30px;">
</div></td>
<?php
for ($s=1;$s<=count($days)-6;$s++) {
?>
<td><div class="col-xs-2">
<input class="form-control input-lg" name="Subject[]" id="Subject<?php echo $j.$s ?>" type="text" value="" style="width:120px; height:30px;">
<input class="form-control input-lg" name="Day[]" id="inputlg" type="hidden" value="<?php echo $days[$s]; ?>" style="width:120px; height:30px;">
</div></td>
<?php
}
echo "</tr>";
}
这是我的PHP代码
$Sub = $_POST['Subject'];
print_r($Sub);
它实际上发送了值,但我没有得到任何响应。我正在用它结巴任何帮助都将非常感谢
编辑:
我听说map或每个函数都可以这样做,但我不知道如何使用($j=0;$j)的函数
for ($j=0;$j<2;$j++) {
?>
<form>
<tr><th><div class="col-xs-2">
<input class="form-control input-lg" name="Time[]" id="inputlg" type="text" value="" style="width:120px; height:30px;">
</div></td>
<?php
for ($s=1;$s<=count($days)-6;$s++) {
?>
<td><div class="col-xs-2">
<input class="form-control input-lg" name="Subject[]" id="Subject<?php echo $j.$s ?>" type="text" value="" style="width:120px; height:30px;">
<input class="form-control input-lg" name="Day[]" id="inputlg" type="hidden" value="<?php echo $days[$s]; ?>" style="width:120px; height:30px;">
</div>
</td>
<?php
}
echo "</tr>";
} ?>
<input type="button" id="btnSubmit" value="sub">
</form>
控制台中有错误吗?没有,显示成功警报,状态200 OK您看到网络中传递到服务器的数据了吗request@Tushar我有一个主题数组,比如主题[0],主题[1]……我需要发送所有这些,这就是问题所在。我可以通过这个代码发送一个值nx,这正是我想要的
for ($j=0;$j<2;$j++) {
?>
<form>
<tr><th><div class="col-xs-2">
<input class="form-control input-lg" name="Time[]" id="inputlg" type="text" value="" style="width:120px; height:30px;">
</div></td>
<?php
for ($s=1;$s<=count($days)-6;$s++) {
?>
<td><div class="col-xs-2">
<input class="form-control input-lg" name="Subject[]" id="Subject<?php echo $j.$s ?>" type="text" value="" style="width:120px; height:30px;">
<input class="form-control input-lg" name="Day[]" id="inputlg" type="hidden" value="<?php echo $days[$s]; ?>" style="width:120px; height:30px;">
</div>
</td>
<?php
}
echo "</tr>";
} ?>
<input type="button" id="btnSubmit" value="sub">
</form>
<script type="text/javascript">
$(document).ready(function() {
$("#btnSubmit").click(function() {
var str = $( "form" ).serialize();
$.ajax({
url: 'newpage.php',
type: 'post',
data: str,
success: function(data) {
alert(data);
},
error: function(data) {
alert("ERRRR");
}
})
});