当前位置: 动力学知识库 > 问答 > 编程问答 >

ajax requst with php code (without php file)

问题描述:

I am doing some table that loads data from sql with limit 20 and offset 0, i want on click on next page number, ajax request that will change that offset to 20 and display the resulting data. so i have nice php function that does it perfectly but i do not wish to make a new php file just for ajax.

here is my table pic

<table class="ui red table">

<thead>

<tr>

<th>თარიღი</th>

<th>მასალა</th>

<th>რაოდენობა</th>

</tr>

</thead>

<tbody>

<?PHP

$mainStockTable = new EchoStock($mysqli, "mainstock", 20);

$mainStockTable->ManualTransactionListTable(0);

?>

</tbody>

<tfoot>

<tr>

<th colspan="3">

<div class="ui right floated pagination menu">

<a class="icon item">

<i class="left chevron icon"></i>

</a>

<a class="item">1</a>

<a class="item">2</a>

<a class="item">3</a>

<a class="item">4</a>

<a class="icon item">

<i class="chevron left icon"></i>

</a>

</div>

</th>

</tr>

</tfoot>

</table>

So what i want is something like:

the PHP ManualTransactionList Table echos as many times as needed

$('a').click(function(){

$pageNum = this.text();

$.AJAX({

PHPcode: <?PHP

$mainStockTable = new EchoStock($mysqli, "mainstock", 20);

$mainStockTable->ManualTransactionListTable(0);

?>

success: function(response){

$('table').html(response);

}

});

网友答案:

You can't make an AJAX request without a file:

This here:

    $.AJAX({
     PHPcode: <?PHP
                $mainStockTable = new EchoStock($mysqli, "mainstock", 20);
                $mainStockTable->ManualTransactionListTable(0);
            ?>
     success: function(response){
        $('table').html(response);
    }

The PHP code only gets executed server-side not client-side.The client, a.k.a. the browser does not "understand" PHP, only the server does.

分享给朋友:
您可能感兴趣的文章:
随机阅读: