无刷新提交表单(非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>
View Code

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);
        }
    });
}
View Code

 

posted @ 2014-12-20 21:00  0611163  阅读(467)  评论(6编辑  收藏  举报