I have following code:
<script type="text/javascript">
<!-- PAGER
var pag = 1;
var loading = false;
var pag1 = <?php echo $k1; ?>;
var pag2 = <?php echo $k2; ?>;
var max_pages_number = <?php echo $max_pages_number; ?>;
jQuery('body').on('click',"#registry_show_more",function(){
if(pag < max_pages_number && !loading) {
loading = true;
jQuery(this).hide();
jQuery("#spinner").show();
alert(pag1 + ' ' + pag2); //alert 1
jQuery.ajax({
type: 'POST',
url: '<?php echo admin_url('admin-ajax.php'); ?>',
data: {
action: 'registry_paggination',
page: pag+1,
p1: pag1,
p2: pag2,
page_size: <?php echo $page_size; ?>,
category: <?php echo $kategoria; ?>,
category_slug: '<?php echo $kategoria_slug; ?>',
filtr: '<?php echo $filtr; ?>',
access: <?php echo $access; ?>,
},
success: function(data, textStatus, XMLHttpRequest){
pag++;
jQuery("#spinner").hide();
if(pag < max_pages_number) {
jQuery('#registry_show_more').show();
}
if(data) {
jQuery("#newpages").append(jQuery("#newpages").html() +data);
FB.XFBML.parse();
jQuery('.open-iframe-lightbox').magnificPopup({type:'iframe'});
pag1 = parseInt(jQuery("#p1").attr('value'),10);
pag2 = parseInt(jQuery("#p2").attr('value'),10);
alert(pag1 + ' ' + pag2); //alert 2
jQuery("#p1").remove();
jQuery("#p2").remove();
}
loading = false;
},
error: function(MLHttpRequest, textStatus, errorThrown){
jQuery("#spinner").hide();
}
});
}
});
//-->
</script>
Variables pag, pag1, pag2
update after success function. I know it because i use two alerts to check it. But ajax function send default values.
For example:
initial values:
pag = 1;
pag1 = 18;
pag2 = 2;
first alert shows:
"18 2"
ajax sends:
page: 2,
p1: 18,
p2: 2
//skiping the rest of variables
second alert shows(just updated):
"35 5"
All fine but on the next click:
first alert shows: - ok
"35 5"
ajax sends: - not ok
page: 2,
p1: 18,
p2: 2
//skiping the rest of variables
second alert shows(just updated): - ok, because ajax send the same data as before
"35 5"
I don't know why AJAX function sends every time the same data not new updated values.
I started to think, It seems that the variables in DATA section in AJAX function are not the same as global variables pag,pag1,pag2 or they are constant.
I hope the example is clear enough.
Thanks in advance for your answer
.
.
.
.
Edit: I managed to solve the problem. Problem was something else. I've used. Append () is add new data but when i used. Html () all works properly. Sorry for the inconvenience.