format.js not working in rails 2 -
i have 2 controller named client/orders
, notary/orders
. have click_me link in "client/orders".when click link should pass ajax request notary/orders/pending_orders
, reload notary/orders/pending_orders
page.
this ajax call in client/orders/new
<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" %>
this code in notary/orders/pending_orders
if request.xhr? respond_to |format| format.js { render :js=>'location.reload();', :location => "notary/orders/pending_orders"} end end
but reloads client/orders/new
not notary/orders/pending_orders
.but want reload notary/orders/pending_orders.how can this?
i guess link <%= link_to "click me", "javascript:void(0);" , :class => "test_link" %>
in client/orders/new
, want update page notary/orders/pending_orders
client/orders/new
.
since making request client/orders/new
, response update in client/orders/new
only.
it seems doing action in client/orders/new
1 browser , listening page notary/orders/pending_orders
in browser update notification when changes happened in back-end.
to update page (eg: showing notification in notary/orders/pending_orders
) automatically when change happened in back-end, use is, put separate listener this,
<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 update browser view } else{ settimeout(notificationlistener(),10000) } }, error:function(){ // } }); } </script>
Comments
Post a Comment