2013-04-05 5 views
0

client/ordersnotary/orders이라는 컨트롤러가 두 개 있습니다. "client/orders"에 click_me 링크가 있습니다. 링크를 클릭하면 notary/orders/pending_ordersreload the notary/orders/pending_orders 페이지로 아약스 요청을 전달해야합니다. format.js가 레일에서 작동하지 않습니다. 2

는/클라이언트/주문 새로운 내 아약스 전화입니다

<script> 
    jQuery.noConflict(); 
jQuery(document).ready(function(){ 
alert(9); 
jQuery(".test_link").live("click", function(){ 
    alert("am clicked"); 
     jQuery.ajax({ 
     url: "/notary/orders/pending_orders", 
     dataType: 'script', 
     type: "get", 
     data: {data:'hi'}, 
     success:function(){ 
      alert("success"); 
     }, 
     error:function(){ 
      alert("failure"); 
     } 
    }); 
}) 

});

<%= link_to "click me", "javascript:void(0);" , :class => "test_link" %> 

이 내가이 작업을 수행 할 수 있습니다 pending_orders.How/

if request.xhr? 
    respond_to do |format| 
    format.js { render :js=>'location.reload();', 
    :location => "notary/orders/pending_orders"} 
    end 
    end 

하지만 다시로드 client/orders/new하지 notary/orders/pending_orders는 나누었다 내가 공증/주문을 다시로드 할 notary/orders/pending_orders 내 코드?

답변

1

나는 <%= link_to "click me", "javascript:void(0);" , :class => "test_link" %>client/orders/new에있는 링크를 생각하면 client/orders/new에서 페이지 notary/orders/pending_orders를 업데이트합니다.

client/orders/new에서 요청을 보내므로 모든 응답은 client/orders/new에서만 업데이트됩니다.

한 브라우저에서 client/orders/new의 작업을 수행하고 있고 다른 브라우저에서 notary/orders/pending_orders 페이지를 수신하는 중 일부 변경 사항이 백엔드에서 발생했을 때 알림을 업데이트하는 것처럼 보입니다.

페이지를 업데이트하려면 (예 : notary/orders/pending_orders에서 알림을 표시) 변화가 백 엔드에서 일어난 자동으로 때, 내가 무엇을 사용, 나는이 같은 무언가에 대한 별도의 수신기를 넣어 것입니다

<script type="text/javascript"> 
     jQuery(document).ready(function(){ 
     notificationListener(); 
     }); 

     function notificationListener(){ 
     jQuery.ajax({ 
      url: "/notary/orders/pending_orders", 
      type: "get", 
      data: {data:'yourdata'}, 
      success:function(){ 
      if(expected result){ 
       //code to update browser view 
      } 
      else{ 
       setTimeout(notificationListener(),10000) 
      } 
      }, 
      error:function(){ 
       // 
      } 
     }); 
    } 

</script> 
+0

대답이 나에게 더 많은 아이디어를주었습니다. 답장을 보내 주셔서 감사합니다. – Inaccessible

관련 문제