0

I list some values on one PHP page. After that, page scrolling needs to display the remaining values. For this, I added the ajax function on the same page. I have a ajax call like :

page = 1;
$.ajax({
                url: test.php/category/?+"ajaxload=true&page="+page ,
                dataType: "html",
                success: function(html) {
                }
});

From the above function, I passed the ajaxload and page variables. After that, I tried to retrieve these variables by using

$ajaxload = $_GET['ajaxload'];
$page     = $_GET['page'];

But I didnt get any value. I am using the core PHP. So I defined the ajax function and retrieving the input value on the same page.

12
  • I tried with this also. But I got the same result. Commented Jul 27, 2021 at 16:27
  • How exactly are you looking at the values? It's not clear Commented Jul 27, 2021 at 16:30
  • I want to retrieve the values of ajaxload and page from my ajax url Commented Jul 27, 2021 at 16:31
  • That means $ajaxload = true and $page =1 Commented Jul 27, 2021 at 16:33
  • 1
    The default is to do exactly that when you leave method: property blank Commented Jul 27, 2021 at 16:40

1 Answer 1

1

Since you are using the same page for ajaxload at the top you should add the below code

    <?php
    if(isset($_GET['ajaxload']) && $_GET['ajaxload'] == true){
    //PLACE YOUR QUERY  and get the result here
    $tr = '<tr><td>'.$result_value_1.'</td><td>'.$result_value_2.'</td><tr>';
    echo $tr;
    exit;
    }
    ?>

since ajax call needs an echo so you need to echo the tr of your table. I have used "exit" so that the response of the ajax call does not contain rest of the content of the page

In you ajax function please make sure the url is correct and then append the tr received from the ajax call below.

<script type="text/javascript">
            $(function() {
                page = 1;
                $.ajax({
                    url: "YOUR_PAGE_NAME.php?ajaxload=true&page="+page,
                    dataType: "html",
                    success: function(html) {
                        $('#TABLE_ID_GOES_HERE').append(html);
                    }
                });

            });
        </script>

I have used table just as reference if your html uses div tags then you can change it accordingly

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.