HTML code:
<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 code:
If the save is successful, the background returns {"ok":true}; if the save fails, the background returns {"ok":false, "msg":"error message"}
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); } }); }
Isn’t it very simple? If friends need it, just take it away, you’re welcome^_^
For more related articles on how to implement refresh-free submission forms without using ajax, please pay attention to the PHP Chinese website!