无刷新提交表单(非Ajax实现)
HTML代码:
<iframe id="fra" name="frm" style="display: none;"></iframe> <form id="frm" method="post" action="@Url.Content("~/Backstage/MachineMng/RoadSet/SaveTrackRoad")?roadId=@ViewBag.roadId" target="frm"> 这里是表单内容 </form>
JS代码:
若保存成功,后台返回{"ok":true};若保存失败,后台返回{"ok":false, "msg":"错误信息"}
function save() { $("#frm").submit(); $("#fra").one("load", function () { var data = eval("(" + $("#fra").contents().find("body").html() + ")"); if (data.ok) { $("#divtrackroad").load("TrackRoad?roadId=" + '@ViewBag.roadId' + "&roadName=" + '@ViewBag.roadName' + "&viewOrEdit=1&t=" + new Date().valueOf()); } else { alert("保存失败:" + data.msg); } }); }