前端jq中的ajax中使用return or retuen false

1.当使用form表单进行ajax提交的时候,使用return时,ajax照提交数据到后端,并不能阻止提交事件,return false可以阻止提交。

如:

$('#call-center-assign-company-form').on('beforeSubmit', function(){
    var form = $(this);
    $.post(form.attr('action'), form.serialize(), function(rs){
        if(rs.status === 200)
        {
            var html = '';
            for(var i=0; i<rs.company.length; i++){
               
                html += "<tr><td class='text-center'>" + rs.company[i]['id'] + "</td><td class='text-center'>" + rs.company[i]['name'] + "</td><td class='text-center'><button type='button' class='btn btn-xs btn-danger delete-btn' data-target='#delete-modal' data-toggle='modal' data-id='"+ rs.company[i]['aid']+ "'>删除</button></td></tr>";
            }
            $("#opportunity-items").html(html);
            // $('#add-modal').modal('hide');
            window.location.reload();
        }
        else
        {
            form.find('.warning-active').text(rs.message);
        }
    }, 'json');
    return false;
});

2.如是非表单提交,return 和return false都可以阻止提交

如删除事件

$('.delete-btn').unbind();
$('.delete-btn').click(function(){
    var id = $(this).attr('data-id');
    $('.delete-sure-btn').unbind();
    $('.delete-sure-btn').click(function(){
        $.post('{$deleteUrl}',{id: id},function(rs){
        if(rs.status != 200)
        {
            $('.warning-active').html(rs.message);
        }
        else
           {
            window.location.reload();
        }
    },'json');
    });
});

G

M

T

Detect languageAfrikaansAlbanianArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CroatianCzechDanishDutchEnglishEsperantoEstonianFilipinoFinnishFrenchGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanLaoLatinLatvianLithuanianMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPersianPolishPortuguesePunjabiRomanianRussianSerbianSesothoSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshYiddishYorubaZulu

AfrikaansAlbanianArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CroatianCzechDanishDutchEnglishEsperantoEstonianFilipinoFinnishFrenchGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanLaoLatinLatvianLithuanianMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPersianPolishPortuguesePunjabiRomanianRussianSerbianSesothoSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshYiddishYorubaZulu

Text-to-speech function is limited to 200 characters

Options : History : Feedback : Donate

Close

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券