javascript - ajax post automatically requested a get after submission
扔个三星炸死你
扔个三星炸死你 2017-06-26 10:52:38
0
2
1006

htmlcode

<form method="post" class="form-horizontal">
    <p class="form-group">
        <label class="col-lg-2 control-label">上级权限</label>
        <p class="col-lg-4">
            <select name="pid">
                <option value="0">顶级权限</option>
                {volist name="authRuleRes" id="authRule"}<option value="{$authRule.id}"><?php if($authRule['level']!=0){echo '|';} echo str_repeat('—', $authRule['level']*3)?>{$authRule.title}</option>{/volist}
                                                    
            </select>
        </p>
    </p>

    <p class="form-group">
        <label class="col-lg-2 control-label">权限名称</label>
        <p class="col-lg-8">
            <input type="text" class="form-control" name="title"/>
        </p>
    </p>

    <p class="form-group">
        <label class="col-lg-2 control-label">控制器/方法</label>
        <p class="col-lg-8">
            <input class="form-control" name="name" type="text" />
        </p>
    </p>

    <p class="form-group">
        <p class="col-lg-offset-2 col-lg-8">
            <input class="btn btn-primary" type="submit" value="提交" />
            <input class="btn btn-default" type="reset" value="重置">
        </p>
    </p>
</form>

js code

$('.form-horizontal').submit(function(event) {
    var data = $(this).serialize();
    $.ajax({
        type:"post",
        url:"/authrule/add",
        async:true,
        data:data,
        success:function(res){
            if(res.code == 1){
                Notify(res.msg, 'top-right', '5000', 'success', 'fa-check', true);
                return false;
            }else{
                Notify(res.msg, 'top-right', '5000', 'danger', 'fa-times', true);
                return false;
            }
        }
    })
    return false;
})

The post is submitted normally, but a get is automatically requested after submission. What is wrong?

扔个三星炸死你
扔个三星炸死你

reply all(2)
洪涛

$('.form-horizontal') This selector selects a large range, and event transmission may be triggered twice. It is recommended to write more accurately. For example,
$('.form-horizontal input[type=submit ]')

某草草

This is very common, is it cross-domain?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template