,这是我的代码:
的观点:
<script>
function update_ref_field(){
var ref_value = $('#ref1').val();
var url = '/ModController/update_ref_field/?ref1='+ref_value;
$.ajax({
type: "POST",
url: url,
//dataType: "jsonp",
// You can use this jsonp if your request related to cross domain
error: function (result, status, xhr){
alert('result='+result+'::status='+status+'::xhr= '+ xhr);
alert('Error occurred while updating the record.'); },
success: function(result, status, xhr){
alert('result='+result+'::status='+status+'::xhr= '+ xhr);
alert('Record updated successfully.');
}});
return false;
}
$('#ref1').focusin(function(){
$(this).attr('readonly',false);
$(this).css('border','1px black solid');
})
$('#ref1').focusout(function(){
$(this).attr('readonly',true);
$(this).css('border','0px white solid');
$javascript:update_ref_field();
})
});
DEF update_ref_field()
开始
@ projj = Project.find。(PARAMS [::PROJECT_ID])#projet柯朗
@local_date = Time.new()TO_DATE
控制器上
@sem = caluculer_semaine(@local_date)
@existe_mom_pour_cet_semaine = Mod.find(:所有,:条件=> {:PROJECT_ID => @ projj.id,:semaine => @sem})
#CE CAS对应联合国更新
开始
@ existe_mom_pour_cet_semaine.each do | a |
if(params [:ref1])!=“”|| (params [:ref1])!=无
a.update_attributes(:ref => params [:ref1])
end
if a。保存
闪光[:通知] = “濑一个元旦REF”
别的
闪光[:错误] = “濑ajour FR REF非aboutit”
端
端
救援异常=>电子
把e.message
放e.backtrace.inspect
端
redirect_to的:行动=> '团聚'
端
端
当我使用tag_form
,我正常工作,但我想,关于数据库的变化会在后台
感谢
http://guides.rubyonrails.org/ajax_on_rails.html – DickieBoy 2013-03-15 15:20:46