Home > Web Front-end > JS Tutorial > body text

Submit form without refresh without using ajax

高洛峰
Release: 2016-12-16 15:30:47
Original
1066 people have browsed it

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>
Copy after login

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=" + &#39;@ViewBag.roadId&#39; + "&roadName=" + &#39;@ViewBag.roadName&#39; + "&viewOrEdit=1&t=" + new Date().valueOf());
        } else {
            alert("保存失败:" + data.msg);
        }
    });
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template