English 中文(简体)
如何使jquery ajax 反应
原标题:how to render jquery ajax response
  • 时间:2012-05-25 06:12:44
  •  标签:
  • jquery
  • ajax

我对jquery ajax很新奇,我正试图弄清楚我怎样才能从 php 作为json的php 中找到回应数据来更新一个指定的 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 代码看起来一样,或者可以用另一种方式完成?

问题回答

假设您想要生成用户定义的 html, 那么可以使用微电子平和 < a href="http:// ejohn. org/blog/javascamp- mic- templation/" rel="nofollow" > MicroTemplating

希望这就是你想要的

$parents.(response).fadeIn();

应该是

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

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

< a href=" "http://api.jquery.com/html" rel="no follow" >.html () 更新了祖父母的内容

有关.text ()

您需要使用 html 或文本方法来删除此功能

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

or 

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

而不是 $proupers. (答复). fadeIn ();





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签