简体   繁体   English

如何通过ajax调用从上一页发送的php页面中获取变量

[英]How to get the variables in php page sent from previous page via ajax call

I am making an ajax call from one php page to second.in which im sending three variables. 我正在从一个php页面到second.in进行ajax调用,其中我发送了三个变量。 But im not able to get it in next php page where im sending them ... please check. 但是即时通讯无法在将其发送给我的下一个PHP页面中获取它...请检查。 Index.php Index.php

function loadMoreData(offset){
var part1= "<?php echo ($part1);?>"; 

var part2="<?php echo ($part2);?>";

    $.ajax({
        type: 'get',
        async:false,
        url: 'getMoreData.php',
        data:{offset:offset,part1:part1,part2:part2},
        success: function(data){

            $(data).appendTo("#product");
        },
        error: function(data){
            alert("ajax error occured…"+data);
        }
    }).done(function(){
        $(window).bind("scroll",function(){
        scrollMore();   
    });
    });
}


});

getMoredata.php getMoredata.php

 <?php
    include('connection.php');

    $offset = (isset($_REQUEST['offset']) && $_REQUEST['offset']!='') ? $_REQUEST['offset'] : '';
    $limit = 10;
    $var1 = (isset($_REQUEST['part1']) && $_REQUEST['part1']!='') ? $_REQUEST['part1'] : '';

    $var2 = (isset($_REQUEST['part2']) && $_REQUEST['part2']!='') ? $_REQUEST['part2'] : '';

    $qry1 = mysql_query('select * from xml WHERE  PNAME LIKE  \'%$var2\' AND CATEGORY like \'%$var1\' limit ".$offset.", ".$limit."');
    print $qry1;
    ?>

I m able to send the three variables from index.php page but im not able to get them in getMoreData.php,due to which im not able to run the sql command... 我能够从index.php页面发送三个变量,但由于无法运行sql命令,因此无法在getMoreData.php中获取它们。

Please verify guys.... 请验证一下...。

尝试所有变量

$offset = isset($_GET['offset']) ? $_GET['offset'] : $_POST['offset'];

Use $_GET instead of $_REQUEST . 使用$_GET代替$_REQUEST

Also you are not sending the rows properly, use- 另外,您没有正确发送行,请使用-

print_r(mysql_fetch_array($qry1));

Then try to check the response in browser's console with - console.log(data) and then manipulate it accordingly. 然后尝试使用console.log(data)在浏览器的控制台中检查响应,然后进行相应的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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