鍍金池/ 問答/PHP  HTML/ ajax提交表單以后,頁面會彈回頂部

ajax提交表單以后,頁面會彈回頂部

基于laravel做的一個表單提交功能,每次填寫完表單,點擊提交時,會顯示提交成功,但頁面會彈回到頁面頂部,這事為什么?
頁面效果截圖:

clipboard.png

clipboard.png

HTML代碼:

<div class="d-flex flex-column justify-content-between align-items-center mb-5">
    <h3 class="contact-text text-uppercase">send us message if you have any questions</h3>
    <div class="d-flex flex-column justify-content-between align-items-center w-75"> 
        <div class="form-group">
            <label for="exampleFormControlInput1">Your Name</label>
            <input type="text" name="name" class="form-control" placeholder="How could we address you?" id="form-name">
        </div>
        <div class="form-group">
            <label for="exampleFormControlInput1">Working Email</label>
            <input type="email" name="email" class="form-control" placeholder="name@example.com" id="form-email"> 
        </div>
        <div class="form-group">
            <label for="exampleFormControlInput1">Cell Phone</label>
            <input type="phone" name="phone" class="form-control" placeholder="+CountryCode ..." id="form-phone">
        </div>
        <div class="form-group">
            <label for="exampleFormControlTextarea1">Your Question</label>
            <textarea class="form-control" name="question" rows="3" placeholder="Please enter your info" id="form-question"></textarea>
        </div>
        <button class="btn btn-outline-primary btn-lg" id="submit-form" onclick="ajaxseed();return false;">Send Message</button>
    </div> 
</div>

JS代碼:

// form sublime
function ajaxseed() {
    var name = $('#form-name').val();
    var email = $('#form-email').val();
    var phone = $('#form-phone').val();
    var question = $('#form-question').val();
   
    $.ajax({
        type: "POST",
        url: url,
        data: data,
        headers: {
            'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
        },
        success: function(){
            swal('success', 'We received your advise', 'success');
            $('#form-name').val('');
            $('#form-email').val('');
            $('#form-phone').val('');
            $('#form-question').val('');
        }
    });
};
回答
編輯回答
夢若殤

你的swal函數(shù)中做了什么處理?

2017年3月23日 01:50
編輯回答
近義詞

表單的submit默認(rèn)事件會自動刷新頁面,可能是這個問題

2017年12月2日 02:33
編輯回答
瘋浪

阻止了表單的默認(rèn)事件了么?

2018年6月12日 10:02