我有一个表单,当我这样调用它时,它可以正常工作,并且会触发AJAX,并且我可以返回data
并对其发出警报。
有效的jQuery
$(".loginFormAddMoreSetlist").submit(function () {
var id = $(this).attr('id');
$.ajax({
type: "POST",
url: "../includes/addmoresetlist.php?",
data:({id: id}),
success: function(data) {
alert(data);
}
});
});
出于某种原因,当我通过添加
var searchsongaddmore = $('input[name="searchsongaddmore[]"]');
对其进行更改时,它会破坏AJAX,实际上会进入addmoresetlist.php文件jQuery的不起作用
$(".loginFormAddMoreSetlist").submit(function () {
var id = $(this).attr('id');
var searchsongaddmore = $('input[name="searchsongaddmore[]"]');
$.ajax({
type: "POST",
url: "../includes/addmoresetlist.php?",
data:({id: id, searchsongaddmore: searchsongaddmore}),
success: function(data) {
alert(data);
}
});
});
的HTML
这种形式允许用户根据需要添加更多字段,以便从中获取数组。看起来像这样
<form class="loginFormAddMoreSetlist" id="<?=$row1[0]?>" action="../includes/addmoresetlist.php">
<div class="row">
<div class="form-group form-group-options col-xs-11 col-sm-8 col-md-7">
<div class="input-group input-group-option col-xs-12" id="searchsongcontainer">
<input class="form-control searchsong" name="searchsongaddmore[]" id="searchsongaddmore" type="text" placeholder="Type Something" />
<input class="form-control searchsonghidden" name="searchsonghidden[]" id="searchsonghidden" type="hidden" />
<span class="input-group-addon input-group-addon-remove">
<span class="fa fa-remove fa-sm"></span>
</span>
</div>
</div>
</div>
<div class="form-group">
<button class="btn btn-info" type="submit">Update</button>
</div>
</form>
最佳答案
您可能正在尝试访问您的<input />
值。使用.val()
尝试以下操作
var searchsongaddmore = $('input[name="searchsongaddmore[]"]').val();