js代码
function AjaxInitForm(formId, btnId, isDialog, urlId){
var formObj = $('#' + formId);
var btnObj = $("#" + btnId);
var urlObj = $("#" + urlId);
formObj.Validform({
tiptype:3,
callback:function(form){
//AJAX提交表单
$(form).ajaxSubmit({
beforeSubmit: formRequest,
success: formResponse,
error: formError,
url: formObj.attr("action"),
type: "post",
dataType: "json",
timeout: 60000
});
return false;
}
});
//表单提交前
function formRequest(formData, jqForm, options) {
btnObj.prop("disabled", true);
btnObj.val("提交中...");
}
//表单提交后
function formResponse(data, textStatus) {
if (data.status == 1) {
btnObj.val("提交成功");
//是否提示,默认不提示
if(isDialog == 1){
$.dialog.tips(data.msg, 2, "32X32/succ.png", function(){
if(data.url){
location.href = data.url;
}else if(urlObj.length > 0 && urlObj.val() != ""){
location.href = urlObj.val();
}else{
location.reload();
}
});
}else{
if(data.url){
location.href = data.url;
}else if(urlObj){
location.href = urlObj.val();
}else{
location.reload();
}
}
} else {
$.dialog.alert(data.msg);
btnObj.prop("disabled", false);
btnObj.val("再次提交");
}
}
//表单提交出错
function formError(XMLHttpRequest, textStatus, errorThrown) {
$.dialog.alert("状态:" + textStatus + ";出错提示:" + errorThrown);
btnObj.prop("disabled", false);
btnObj.val("再次提交");
}
}
前台
$(function () {
//初始化评论列表
AjaxPageList('#comment_list', '#pagination', 10, @ViewData["comment_count"], '/Base/Process?action=comment_list&article_id=@ViewData["article_id"]', '/images/user_avatar.png');
//初始化发表评论表单
AjaxInitForm('comment_form', 'btnSubmit', 1);
});
datatype="*" sucmsg=" ">
验证码:
errormsg="请填写4位验证码" sucmsg=" " οnkeydοwn="if(event.ctrlKey&&event.keyCode==13){document.getElementById('btnSubmit').click();return false};" />
src="@Url.Action("SecurityCode")" οnclick="this.src=this.src+'?'" />
[HttpPost]
public ActionResult comment_add()
{
return Json("fdsfdsfds");
}
发表评论共有 @ViewData["comment_count"]访客发表了评论
暂无评论,快来抢沙发吧!