English 中文(简体)
使用jquery/ajax
原标题:Page not updating when using jquery/ajax

我制作一个网站,让人们在购物车上添加课程。 我有一个“Cart”模式,它具有“many LineItems”。

在车上,我有一个麻省,让人们去除个别线项目。 罚款。 这部法典:

•line_item.html.erb:

<div class="delete_line_item"><%= button_to  Delete , line_item, 
{:method => :delete, :remote => true} %></div>

第1行——项目控制器:

  def destroy
    @user = current_user
    @line_item.destroy
    @cart = @user.cart

    respond_to do |format|
      format.html { redirect_to(root_path) }
      format.js
      format.xml  { head :ok }
    end
  end

之后,位于我的看法/线——项目夹内的销毁卷宗:

$("#cart").html("<%= escape_javascript(render(@cart)) %>");

我也想做一些类似的事情,以 empty开车。 为了做到这一点,我会利用各条控制器的最新行动。 这里对应的密码库:

<div class="empty_cart"><%= button_to  Empty cart , cart, {:method => :put, :remote => true, 
:confirm =>  Are you sure? } %></div>

#carts controller
  def update
    if @cart.line_items
      @cart.line_items.each do |item|
        item.destroy
      end 
    end 

    respond_to do |format|
      if @cart.update_attributes(params[:cart])
        format.html { redirect_to(root_path, :notice =>  Cart emptied. ) }
        debugger
        format.js
        format.xml  { head :ok }

最后,本文载有最新情况。 我在我的意见/文章中说:

$("#cart").html("<%= escape_javascript(render(@cart)) %>");

问题在于,当我试图空出车时,这项请求已经过去(当我重新接过这页时,车库是空洞的),但变化并没有立即点击。 这使我想,我的浏览器根本不提供文件。 是否需要将更新档案放在不同的文件夹中或改名为档案? 或者还有什么事情在进行?

问题回答

Instead of using the update action, why don t you just use the destroy action for the cart instead of using the update? That s what I did, and it worked.





相关问题
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 ...

热门标签