1

私はjquery ajaxを初めて使用し、phpから返された応答データをjsonとしてレンダリングして、指定されたdivを更新する方法を理解しようとしています。したがって、実際には次の問題があります。

JavaScript:

<script type="text/javascript">
  $(document).ready(function() {
    $(".ajax_call").change(function() {
      var domain = document.domain;
      var count = $('.ajax_call :selected').val();
      var $parent = $(this).closest(".product_box");
      var modul_title = $("h4", $parent).text();
      $.ajax({
        url:'index/ajax',
        data:{mod_title:modul_title, domain:domain, count:count},
        cache:'false',
        datatype:'json',
        success: function(response) {
          if (response.status = modul_title) {
            $parent.fadeOut();
            $parents.(response).fadeIn();                            
          } else {
            alert("Oops, script is a no go");
          }    
        }   
      });
   });
});

そしてHTML:

<div class="product_box">
  <h4><!-- php code generating --> header</h1>
  <div class="product">
    <div class="thumbnail-item">
      <a href=""></a>
      <!-- and couple of other divs what are rendering my output in my mvc view -->
      <div class="ajax_bar">
        <!-- and here comes the dropdown what is triggering an ajax call -->
        <select class="ajax_call" size="1" name="blala">
          <option value='50'>add more 50</option>
          <option value='100'>add more 100</option>
          <option value='150'>add more 150</option>
        </select>
      </div>
    </div>
  </div>
</div>

私が欲しいのは、提示されたアイテムの数をajax呼び出しで更新することです。応答をレンダリングする方法がわかりません。私のhtml-phpコードが見えるように、生データを再度形成する必要がありますか、それとも別の方法で行うことができますか?

4

3 に答える 3

1

ユーザー定義の html を生成したい場合は、microtemplating を使用できます。MicroTemplating

これがあなたが望むものであることを願っています。

于 2012-05-25T06:15:32.773 に答える
0
$parents.(response).fadeIn();

する必要があります

$parents.html(response).fadeIn(); 

また

$parents.text(response).fadeIn(); 

.html() $parents のコンテンツを更新します

.text()について読む

于 2012-05-25T06:13:46.060 に答える
0

これを表示するには、htmlまたはテキストメソッドを使用する必要があります

$parents.html(response).fadeIn();

or 

$parents.text(response).fadeIn();

それ以外の$parents.(response).fadeIn();

于 2012-05-25T06:15:29.150 に答える