74 lines
1.9 KiB
JavaScript
74 lines
1.9 KiB
JavaScript
var xform = {
|
|
submit : function(){
|
|
data = $('#'+configure.formid).serialize();
|
|
$.ajax({
|
|
'type':"POST",
|
|
'url':configure.requesturl,
|
|
'data':data,
|
|
'success':xform.onsuccessed,
|
|
'timeout': 30000,
|
|
'error': function(){
|
|
$("#alert-info").attr('class','alert alert-error');
|
|
$("#alert-info").html("出现错误,请稍后重试");
|
|
$('#submit-loading').hide();
|
|
return false;
|
|
},
|
|
'beforeSend': function(){
|
|
$("#submit_btn").addClass('disabled');
|
|
$("#submit_btn").attr('disabled','disabled');
|
|
$('#submit-loading').show();
|
|
},
|
|
'complete': function(){
|
|
$("#submit_btn").removeClass('disabled');
|
|
$("#submit_btn").removeAttr('disabled');
|
|
$('#submit-loading').hide();
|
|
}
|
|
});
|
|
},
|
|
onsuccessed : function(data){
|
|
if (typeof(data)=='object')
|
|
{
|
|
if(typeof(data.error)!='undefined')
|
|
{
|
|
$("#alert-info").attr('class','alert alert-error');
|
|
$("#alert-info").html(data.error);
|
|
return false;
|
|
}
|
|
if(typeof(data.success)!='undefined')
|
|
{
|
|
$("#alert-info").attr('class','alert alert-success');
|
|
$("#alert-info").html("添加成功!");
|
|
setTimeout("$('#mdref-form').modal('hide');",1000);
|
|
setTimeout("window.location.href = window.location.href",2000);
|
|
return false;
|
|
}
|
|
}
|
|
else{
|
|
$("#alert-info").attr('class','alert alert-error');
|
|
$("#alert-info").html('请求中发生错误,请重试');
|
|
return false;
|
|
}
|
|
},
|
|
edit : function(field)
|
|
{
|
|
for(i in field)
|
|
{
|
|
this.attr = $('#'+configure.formid+' input[name='+i+']').attr('type');
|
|
if( this.attr == 'radio')
|
|
{
|
|
$('input[name='+i+']').each(function(index, element) {
|
|
if($(this).val() == field[i])
|
|
{
|
|
$(this).attr('checked','checked');
|
|
}
|
|
});
|
|
}
|
|
|
|
if(this.attr == 'text')
|
|
{
|
|
$('#'+configure.formid+' input[name='+i+']').val(field[i]);
|
|
}
|
|
}
|
|
this.attr = null;
|
|
}//edit
|
|
} |