ajax提交
<form> <div id="button"> <button type="button" class="btn btn-primary" style="width: 120px;height: 40px;" onclick="pc_creat_live()">创建直播</button> </div> </form> function pc_creat_live() { var title = $("#title").val(); var plan_start_time = $("#plan_start_time").val(); var shop_id = $("#shop_id").val(); if (title == '') { $(".tips_span").text('*主题不能为空').show(); } else if (plan_start_time == '') { $(".tips_span").text('*时间不能为空').show(); } else if (shop_id == '') { $(".tips_span").text('*店铺id不能为空').show(); }else { $.ajax({ url: "/mini_wechat/creat_live_pc/", data: { csrfmiddlewaretoken: "{{csrf_token}}", shop_id: shop_id, title: title, plan_start_time: plan_start_time }, type: "POST", dataType: "json", success: function (results) { if (results["is_succ"]) { if ('{{ back_url }}') { window.location.href = '{{ back_url }}' } else if (results['back_url']) { window.location.href = '' + results['back_url'] } else { window.location.href = '/' } } else { $(".tips_span").text(results['msg']).show(); } } }) } }
或者 ps;οnsubmit=“reutrn false”
onsubmit:当提交表单时执行一段 JavaScript,则return false表示禁止表单提交.
<form class="form-inline" action="/super_manage/hongren_submitl/" method="post" style="margin-bottom: 10px" onsubmit="return false"> <div class="form-group"> <div class="col-sm-offset-2 col-sm-6"> <button type="submit" class="btn btn-primary" onclick="saveProduct()">保 存</button> </div> </div> </form> function saveProduct() { $.ajax({ url: $("form").attr("action"), data: $("form").serialize(), type: "POST", dataType: "json", success: function (data) { if (data['is_succ']==1) { window.location.href = '/super_manage/unchecked_hongren_list/'; } else { $(".alert").html(data["error_msg"]); showMsg(data.error_msg); } }, error: function () { showMsg("网络繁忙,请重试或稍后再试"); } }); }

浙公网安备 33010602011771号