2012-03-15 118 views
1

我有在紅寶石 periodically_call_remote獲得HTML的輸入值有問題......發送HTML格式的輸入值在阿賈克斯

例如:

我有一個名爲my_input的輸入。現在我想在periodically_call_remote中有這個。

<input name="my_input" /> 

periodically_call_remote(:url=>{:action=>"action_name", :controller=>"controler_name", nvalue=>"value_of_my_input"}, frequency=>"5") 

這是我希望在value_of_my_input中具有輸入值的調用。

軌寶石版本:2.3.5

我將如何做到這一點..?

回答

0

我已經實現了我想要的......它的代碼:

periodically_call_remote(:url=>{:controller=>"controller_name", :action=>"action_name"), :with=>"'name='+jQuery('#id').val()") 

日Thnx您的幫助和時間的兄弟......

0

你需要回應你的動作action_name一個JavaScript腳本來做你輸入的更新。

$('#id_of_my_input').val('<%= @my_new_value %>') 
+0

我不想那樣做.. – 2012-03-16 11:17:17

+1

爲什麼不這樣做? – shingara 2012-03-16 13:18:04

1

我知道你正在使用Rails 2.3.5,但 「periodically_call_remote」 在Rails 3中已過時,所以我建議你使用這樣的事情,而不是:

$(document).ready(function(){ 
setInterval(function(){ 
    $.get('<%= url_for :action=>"action_name", :controller=>"controler_name", :value=>"value_of_my_input" %>', function(value) { 
    $('#my_input').val(value); 
}); 
},5000); 

});

+0

我不想在jQuery中做... – 2012-03-16 11:17:53