【问题标题】:reload just a part of a page after ajax requestajax请求后仅重新加载页面的一部分
【发布时间】:2013-08-11 07:42:51
【问题描述】:

我正在尝试为我的数据列表添加一个搜索模块。

我将请求发布到的函数呈现视图。

按下搜索按钮后如何加载列表网格?

我应该echo 一个html 代码,还是渲染一个视图并将该视图写在那个位置?

我完全糊涂了……

public function actionSell() {
    $cond="";
    if($_POST) {
        foreach ($_POST as $key => $value) {
            $_POST[$key] = str_replace(',', '', stripslashes(mysql_real_escape_string($value)));
        }
        $melk_id = $_POST['melk_id'];
        $city_id = $_POST['city_id'];
        $cost_from = $_POST['cost_from'];
        $cost_to = $_POST['cost_to'];
        $metraj_from = $_POST['metraj_from'];
        $metraj_to = $_POST['metraj_to'];
        if($melk_id) $cond .= ' and melk_id='.$melk_id; 
        if($city_id) $cond .= ' and city_id='.$city_id;
        if($cost_from) $cond .= ' and cost >='.$cost_from;
        if($cost_to) $cond .= ' and cost <='.$cost_to;
        if($metraj_from) $cond .= ' and metraj >='.$metraj_from;
        if($metraj_to) $cond .= ' and metraj <='.$metraj_to;
    }
    $dataProvider = new CActiveDataProvider('Data', array('criteria' => array(
            'condition' => 'type = 0 '.$cond,
            'order' => 'id DESC',
        ),
        'pagination' => array('pageSize' => 15)
    ));
    $this->render('sell', array(
        'dataProvider' => $dataProvider,
    ));
}

【问题讨论】:

    标签: php jquery yii


    【解决方案1】:

    我不是 php 开发人员,但我会尝试以 jQuery 方式回答。

    1. 假设您将列表网格放在一个容器中:&lt;div id="container"&gt; //the grid &lt;/div&gt;

    2. 您从包含网格

    3. View 填充容器
    4. 您有搜索文本框
      &lt;input id="searchBox" type="text" name="SeachTxt" Value="Some text"/&gt;

      还有一个按钮: &lt;input id="SearchBtn" type="button" value="Search Now!"&gt;

    5. 接下来你必须有一个 jQuery ajax post 函数,像这个:

      jQuery("#SearchBtn").click(function(e) {
      e.preventDefault();
      jQuery.ajax({
          url: 'index.php?searchString=' + jQuery("#searchBox").val(),
          success: function(result) {
              jQuery("#container").html(result);
          }
      });
      

      });

    【讨论】:

      【解决方案2】:

      你可以使用renderPartial,比如

      $this->renderPartial('_ajaxContent', array(
                              'dataProvider' => $dataProvider
                          ), false, true
      );
      

      【讨论】:

      • 我将如何在我的 jquery 请求中使用它?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-14
      • 2014-02-16
      • 1970-01-01
      • 1970-01-01
      • 2012-09-03
      • 2019-08-23
      相关资源
      最近更新 更多