search

Home  >  Q&A  >  body text

javascript - ajax post automatically requested a get after submission

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?

扔个三星炸死你扔个三星炸死你2708 days ago982

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-06-26 10:54:38

    $('.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 ]')

    reply
    0
  • 某草草

    某草草2017-06-26 10:54:38

    This is very common, is it cross-domain?

    reply
    0
  • Cancelreply