jQuery ajax回调函数停止后追加接收到的数据和接收到的jQuery脚本不工作
jQuery ajax callback function stop after append received data and received jquery script dont work
我有两个问题与jQuery ajax回调。我有以下jQuery ajax调用代码:
<div id="newpages"></div>
<script type="text/javascript">
<!--
var page = 1;
var max_pages_number = <?php echo $max_pages_number; ?>;
jQuery(document).ready(function(){
jQuery("#registry_show_more").click(function(){
if(page < max_pages_number) {
jQuery.ajax({
type: 'POST',
url: '<?php echo admin_url('admin-ajax.php'); ?>',
data: {
action: 'registry_paggination',
page: page+1,
plusid: 18,
page_size: <?php echo $page_size; ?>,
category: <?php echo $kategoria; ?>,
filtr: '<?php echo $filtr; ?>',
access: <?php echo $access; ?>,
},
success: function(data, textStatus, XMLHttpRequest){
page++;
if(page >= max_pages_number) {
jQuery("#registry_show_more").hide();
}
if(data) {
alert('a');
jQuery("#newpages").append(jQuery("#newpages").html() +data);
alert('b');
}
},
error: function(MLHttpRequest, textStatus, errorThrown){}
});
}
});
});
//-->
</script>
<div style="display: block;" id="registry_show_more">
<a class="w-blog-entry-more g-btn type_default size_small">WCZYTAJ WIĘCEJ</a>
</div>
第一个问题。收到数据后,在ajax回调警报('a')显示,然后数据被附加到div与id="newpages"。但是第二个警报('b')没有显示。
第二个问题。在ajax.php文件中,我有部分代码如下:
<script type="text/javascript">
<!-- plus
jQuery(document).ready(function(){
jQuery("#bp<?php echo $row->registry_id; ?>").click(function(){
if(!jQuery.cookie('regvote<?php echo $row->registry_id; ?>')) {
jQuery.cookie('regvote<?php echo $row->registry_id; ?>','+', { expires: 1 });
jQuery.ajax({
type: 'POST',
url: '<?php echo admin_url('admin-ajax.php'); ?>',
data: {
action: 'registryVote',
plusid: <?php echo $row->registry_id; ?>,
},
success: function(data, textStatus, XMLHttpRequest){
jQuery("#vc<?php echo $row->registry_id; ?>").html(data);
},
error: function(MLHttpRequest, textStatus, errorThrown){}
});
}
});
});
//-->
</script>
<div class="post twc-post type-post status-publish format-standard hentry w-blog-entry">
<div id="votepanel<?php echo $row->registry_id; ?>" style="width: 35px; float: left;">
<a style="cursor:pointer; cursor:hand" id="bp<?php echo $row->registry_id; ?>"><i class="fa fa-plus-square" style="cursor: hand !important; color: #bd2029; font-size: 32px;"></i></a>
<h6 id="vc<?php echo $row->registry_id; ?>" style="margin: 0; padding: 0;"><?php echo number_format((double)$row->value,1); ?></h6>
<a style="cursor:pointer; cursor:hand" id="bm<?php echo $row->registry_id; ?>"><i class="fa fa-minus-square-o" style="color: #bd2029; font-size: 22px;"></i></a>
</div>
<script type="text/javascript">
<!-- minus
//jQuery(document).ready(function(){
jQuery("#bm<?php echo $row->registry_id; ?>").click(function(){
if(!jQuery.cookie('regvote<?php echo $row->registry_id; ?>')) {
jQuery.cookie('regvote<?php echo $row->registry_id; ?>','-', { expires: 1 });
jQuery.ajax({
type: 'POST',
url: '<?php echo admin_url('admin-ajax.php'); ?>',
data: {
action: 'registryVote',
minusid: <?php echo $row->registry_id; ?>,
},
success: function(data, textStatus, XMLHttpRequest){
jQuery("#vc<?php echo $row->registry_id; ?>").html(data);
},
error: function(MLHttpRequest, textStatus, errorThrown){}
});
}
});
// });
//-->
</script>
和脚本MINUS和PLUS不工作,当我把它们附加到div "newpages"。
我不完全确定,但我认为第一个问题是原因,因为你不能使用追加追加一个html文本。你可以附加元素,但直接html不是一个好主意,我认为。尝试使用jQuery("#newpages").html(jQuery("#newpages").html() + data);
代替
关于第二个问题,据我所知,你是追加这些脚本到一个文件后调用?不是文档之后的调用。已经准备好了吗?您正确地附加了脚本,但是脚本在文档之后执行。准备好了哪些已经过去了?抱歉,如果我没有理解正确的时间顺序。
相关文章:
- 用程序搜索JQuery数据表中的文本
- jquery数据表的自定义ko绑定
- jquery数据表在初始化时设置宽度
- 如何通过下拉值更改来更改jquery数据表的值
- 来自应用程序状态的Jquery数据表源
- 根据jquery数据属性值进行查询
- 如何根据某些条件向可编辑的jquery数据表添加或删除按钮
- jQuery-数据提取问题(html遍历)
- 如何在不使用TableTool的情况下从jquery数据表中获取选定的行索引
- 使用xPath从Jquery数据验证程序获取输入
- Jquery 数据表选择位于第 1 页以外的其他页上的行
- jQuery 数据表 在页面上导航时,在分页表上重置行的数据
- 如果我在页面之间移动,Jquery 数据表行事件会卡住
- 引导程序 3 折叠面板中的 Jquery 数据表响应插件
- 为什么不允许在jquery数据表服务器端处理ajax中使用成功
- 对 jQuery 数据表中的所有选定行求和
- 如何使用jquery数据比较两个前后输入值
- 使用jquery数据表,我可以't在不破坏FixedHead的情况下生成单元格colspan=3
- 扩展详细信息Jquery数据表的持久性
- jquery数据表显示/隐藏列添加了错误的选择