使用ajax从第三个页面获取数据

Get data from third page using ajax

本文关键字:三个 获取 数据 ajax 使用      更新时间:2023-09-26

我有一个表单我的条件是,

  1. form.php,在这里我使用表单插入数据,
  2. display.php在这里我使用分页和
  3. 显示表格形式的数据
  4. validation.js在那里我验证表单数据以及我有以下功能

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

现在我想在相同的display.php分页表后显示form.php中的表单。怎么做呢?

新建议:

无论何时在ajax.php中显示数据,只需创建一个会话数组变量并在会话数组变量中更新该值。因此,当您在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>"; 

旧建议:

可以使用$。数据类型为json的Ajax。所以你可以返回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);

            }
        });