【发布时间】:2018-05-01 02:18:47
【问题描述】:
在控制器中
if (!surveyMasterAnswerDetailInstance.save(flush: true)) {
render([success: false, messages: surveyMasterAnswerDetailInstance.errors] as JSON)
return
}
render([success: true] as JSON)
}
//在视图中
$(document).on('submit', '#creationOptionsForm', function(e){
e.preventDefault();
var form_data = new FormData($('#creationOptionsForm')[0]);
var formURL = $(this).attr("action");
$.ajax(
{
url : formURL,
processData: false,
contentType: false,
async: false,
cache: false,
type: "POST",
data : form_data,
success: function(data){
if(data.success == true){ // if true (1)
setTimeout(function(){// wait for 5 secs(2)
location.reload(); // then reload the page.(3)
}, 5000);
}
}
,
error: function(jqXHR, textStatus, errorThrown)
{
//if fails
}
});
return true
});
【问题讨论】: