使用ajax从第三页获取数据

时间:2022-12-03 14:28:12

I have a form my conditions are,

我的表格有条件,

  1. form.php, where I am inserting data using form,
  2. form.php,我使用表单插入数据,

  3. display.php where I am showing data in table form using pagination and
  4. display.php我在表格中使用分页和显示数据

  5. validation.js where I am validating form data as well as I have following function

    validation.js我在哪里验证表单数据以及我有以下功能

     $('#pagiCount a').click(function(){
            $.get($(this).attr('href'), function(response) {
                console.log(response);
                $( "#result" ).html(response);
                });
            return false;
            //alert($(this).attr('href'));
        });
    

Now I want to show that form from form.php on same display.php after pagination table. How I can do that ?

现在我想在分页表之后的同一display.php上显示form.php中的那个表单。我怎么能这样做?

1 个解决方案

#1


0  

New Suggeston :

新建议:

Whenever you display the data in the ajax.php , just create a session array variable and update that value in the session array variable. So when ever you display the value in the ajax.php , get the data from the session array variable and display it.

每当您在ajax.php中显示数据时,只需创建一个会话数组变量并在会话数组变量中更新该值。因此,当您在ajax.php中显示该值时,从会话数组变量中获取数据并显示它。

Code : ajax.php

代码:ajax.php

    while($result=mysql_fetch_array($query)){  
    $_SESSION['compare_array'][]=$result; 
    } 
     echo "<table>"; 

    foreach($_SESSION['compare_array'] as $key => $result)
    { 

        echo '<tr><td>'.$result['brand'].'</td>'.'<td width="150" height="10">'.$result['model'].'</td>'; echo '<td>'.$result['clr'].'</td>'.'<td>'.$result['sim'].'</td>'.'<td>'.$result['os']‌​.'</td>'.'</td></tr>'; 

    } 

echo "</table>"; 

OLD Suggestion :

老顾问:

You can use $.ajax with datatype : json. so you can return the data array in json encoded format so you can return both pagination result data and the form html data in array.

您可以将$ .ajax与数据类型:json一起使用。所以你可以以json编码格式返回数据数组,这样你就可以在数组中返回分页结果数据和表单html数据。

echo json_encode("pagination_response" => "put pagination html here", "form_data_response"  => "put form html here ");


    $('#pagiCount a').click(function(){
                $.get($(this).attr('href'), function(response) {
                    console.log(response);
                    $( "#result" ).html(response);
                    });
                return false;
                //alert($(this).attr('href'));
            });


     $.ajax({
            type: "POST",  // post or get
            url: 'your_url',
            data: "data_href="+ $(this).attr('href'),
            dataType: "json",
            success: function(response)
            { 
        if(result.status =="success")
        { 

            $( "#result" ).html(response.pagination_response);
            $( "#result_form_html" ).html(response.form_data_response);



            }
        });

#1


0  

New Suggeston :

新建议:

Whenever you display the data in the ajax.php , just create a session array variable and update that value in the session array variable. So when ever you display the value in the ajax.php , get the data from the session array variable and display it.

每当您在ajax.php中显示数据时,只需创建一个会话数组变量并在会话数组变量中更新该值。因此,当您在ajax.php中显示该值时,从会话数组变量中获取数据并显示它。

Code : ajax.php

代码:ajax.php

    while($result=mysql_fetch_array($query)){  
    $_SESSION['compare_array'][]=$result; 
    } 
     echo "<table>"; 

    foreach($_SESSION['compare_array'] as $key => $result)
    { 

        echo '<tr><td>'.$result['brand'].'</td>'.'<td width="150" height="10">'.$result['model'].'</td>'; echo '<td>'.$result['clr'].'</td>'.'<td>'.$result['sim'].'</td>'.'<td>'.$result['os']‌​.'</td>'.'</td></tr>'; 

    } 

echo "</table>"; 

OLD Suggestion :

老顾问:

You can use $.ajax with datatype : json. so you can return the data array in json encoded format so you can return both pagination result data and the form html data in array.

您可以将$ .ajax与数据类型:json一起使用。所以你可以以json编码格式返回数据数组,这样你就可以在数组中返回分页结果数据和表单html数据。

echo json_encode("pagination_response" => "put pagination html here", "form_data_response"  => "put form html here ");


    $('#pagiCount a').click(function(){
                $.get($(this).attr('href'), function(response) {
                    console.log(response);
                    $( "#result" ).html(response);
                    });
                return false;
                //alert($(this).attr('href'));
            });


     $.ajax({
            type: "POST",  // post or get
            url: 'your_url',
            data: "data_href="+ $(this).attr('href'),
            dataType: "json",
            success: function(response)
            { 
        if(result.status =="success")
        { 

            $( "#result" ).html(response.pagination_response);
            $( "#result_form_html" ).html(response.form_data_response);



            }
        });