通过POST将数据从JavaScript传递到PHP

时间:2014-02-16 05:03:37

标签: javascript php html post

我无法发送变量lvl_id。我把它放在JavaScript中,我想把它传递给PHP。以下是我的sort.php,我想将其传递给manageusersort.php

sort.php

<script type="text/javascript">
$(document).ready(function() {
    $("#results").load(
        "manageusersort.php",
        {'page': 0},
        function() {$("#1-page").addClass('active');}
    );  //initial page number to load

    $(".paginate_click").click(function(e) {
        $("#results").prepend('<div class="loading-indication"><img src="ajax-loader.gif" /> Loading...</div>');
        var clicked_id = $(this).attr("id").split("-"); // ID of clicked element, split() to get page number.
        var page_num = parseInt(clicked_id[0]);         // clicked_id[0] holds the page number we need

        $('.paginate_click').removeClass('active');     // remove any active class
        // post page number and load returned data into result element
        // notice (page_num-1), subtract 1 to get actual starting point
        $("#results").load(
            "manageusersort.php",
            {'page': (page_num-1)},
            $.POST("manageusersort.php", { lvl_id: "'<?php $lvlid=$_POST['lvlid']; echo $lvlid;?>'"}),
            function() {$('.paginate_click').removeClass('active');}
        );

        $(this).addClass('active');    // add active class to currently clicked element (style purpose)
        return false;                  // prevent going to href link
    });
});
</script>

1 个答案:

答案 0 :(得分:0)

此代码:

$("#results").load(
    "manageusersort.php",
    {'page': (page_num-1)},
    function() {$('.paginate_click').removeClass('active');}
);

已将一些数据传递给manageusersort.php。看起来你把它放在中间:

$.POST("manageusersort.php", { lvl_id: "'<?php $lvlid=$_POST['lvlid']; echo $lvlid;?>'"}),

那会分开做点什么。你可能想要勾起原来的一个:

$("#results").load(
    "manageusersort.php",
    {'page': (page_num-1), lvl_id: /* ... */},
    function() {$('.paginate_click').removeClass('active');}
);