[英]Jquery array contents not shown directly after clicking first radio button
我有以下html:
if(isset($_POST['itemid']))
{
<table class="table table-striped table-condensed table-bordered table-rounded errorcattable">
<thead>
<tr>
<th colspan='4'>Error categorieeen</th>
</tr>
<tr>
<th>Bijbehorend punt</th>
<th>Categorienaam</th>
<th>Error</th>
<th>fix</th>
</tr>
</thead>
<tbody>
<?php
for( $i = 0; $i < count( $getErrorCategories->data ); $i++ ) :
?>
<tr>
<td id='<?php echo $getErrorCategories->data[$i][' item ']; ?>'>
<?php echo $getErrorCategories->data[$i]['item']; ?>
</td>
<td>
<?php echo $getErrorCategories->data[$i]['c_error_cat_name']; ?>
</td>
<td>
<?php echo $getErrorCategories->data[$i]['error']; ?>
</td>
<td>
<?php echo $getErrorCategories->data[$i]['fix']; ?><br/>
<input type='radio'>OK<br/>
<input type='radio'>NOK</td>
</tr>
<?php
endfor;
?>
</tbody>
</table>
}
通过使用以下jquery代码,我将表的内容(在for循环中)存储在数组中:
var ajaxResult = [];
$('.radionok').each(function() {
$(this).click(function() {
$.ajax({
type: 'POST',
data: {
itemid: $(this).attr('alt')
},
url: "cl.php",
success: function(data) {
if ($.inArray($('.errorcattable', data).prop('outerHTML'), ajaxResult) == -1) {
ajaxResult.push($('.errorcattable', data).prop('outerHTML'));
}
}
});
console.log(ajaxResult);
$(".errorcattable_display").show()
$('.errorcattable_display').html(ajaxResult);
});
});
如您所见,当单击具有radionok作为类的按钮时,应该显示数组的内容(即ajaxResult)。 但是,仅当我单击第二个单选按钮等时才显示内容。因此,当单击第一个单选按钮时,什么也没有发生:
当我单击第二个单选按钮时,将显示第一个单选按钮的表,但是当第二个单选按钮存储在数组中时,仍不显示属于第二个按钮的表:
单击第三个单选按钮时会发生相同的情况(然后显示第一个和第二个表,但不显示第三个表),等等。我希望脚本在单击第一个不好的单选按钮时直接显示第一个表,然后在第二个不显示时单击单击确定按钮,应该在第一个表之外显示第二个表,等等。
有人可以解释为什么会发生这种现象,以及如何修改脚本以使其适合我的需求?
解决了。 我需要移动$(".errorcattable_display").show().html(ajaxResult);
进入ajax调用的成功功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.