简体   繁体   中英

How to define the ajax return value

In my project, I use jqpagination. And I want to define the records of each page, so I use select tag in my web page.

The problem is when I change select tag, the value returned from lstajax.php is not the same. sometimes it is xie1, but sometimes it is xie2.

I have tested, the returned value is random. For example, when i chosed 30 first, the value is xie1. When i chosed 30 next time, the value maybe xie1 or maybe xie2.

My js code:

<link rel="stylesheet" href="jsui/jqpagination.css" />  
<script src="jsui/jquery-3.2.1.min.js"></script>  
<script src="jsui/jquery.jqpagination.js"></script>  
<script>
$(document).ready(function()
{
 var rtnv = "<?php session_start();echo $_SESSION['rtNum']?>";
 var pgrNum=$('#pgnId').val();
 var mpn=Math.ceil(rtnv/pgrNum);
 $('.pagination').jqPagination({
 max_page:mpn,
 page_string:'Page {current_page} of {max_page}',
 paged:function(page){
    $.ajax({
        dataType:'html',
        type:"POST",
        url:"lstajax.php",
        data:{pageNum:page,pgrNum:pgrNum},
        success:function(data) 
        {
         $('#div2').html(data);
        }
    });
 }
 });

 $('#pgnId').change(function(){
    var pages="1";
    $('.pagination').jqPagination('option','current_page',pages);
    var rtnvs = "<?php session_start();echo $_SESSION['rtNum']?>";
    var pgrNums=$('#pgnId').val();
    var mpns=Math.ceil(rtnvs/pgrNums);
    $('.pagination').jqPagination('option','max_page',mpns);
    $.ajax({
        dataType:'html',
        type:"POST",
        url:"lstajax.php",
        data:{pageNums:pages,pgrNums:pgrNums},
        success:function(data) 
        {
         $('#div2').html(data);
        }
    }); 
 });
});
</script>   

My lstajax.php code:

<?php

if(isset($_POST['pageNum']))
{   
 echo "xie1";
}

if(isset($_POST['pageNums']))
{
 echo "xie2";
}
?>

My html code:

<div class="pagination" style="clear:both;display:block;margin-left:40%">  
    <a href="#" class="first" data-action="first">&laquo;</a> 
    <a href="#" class="previous"  data-action="previous">&lsaquo;</a>  
    <input type="text" readonly="readonly" data-max-page="80"/>  
    <a href="#" class="next" data-action="next">&rsaquo;</a> 
    <a href="#" class="last" data-action="last">&raquo;</a> 
    <label>eachpage:</label>
    <select name="pgNum" id="pgnId">
        <option value="10">10</option>
        <option value="15">15</option>
        <option value="20"  selected="selected">20</option>
        <option value="30">30</option>
        <option value="40">40</option>
        <option value="50">50</option>
    </select>   
    </div>
var options={'trigger':false}

in the method:

base.cassMthod=function(method,key,value)

in the file:

jquery.jqPagination.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM