Javascript 微调器图标不可见

Javascript 微调器图标不可见,javascript,html,ajax,forms,spinner,Javascript,Html,Ajax,Forms,Spinner,我想在用户单击HTML表单提交按钮时显示微调器图标,并想在数据发布到目标URL时隐藏它。但是,就我而言,它不起作用。下面是我用于此函数的代码: function PostData(){ var validation=false; jQuery("#training_submit").prop('disabled', true); jQuery('#error_traff').hide(); jQuery('#error_epost').hide();

我想在用户单击HTML表单提交按钮时显示微调器图标,并想在数据发布到目标URL时隐藏它。但是,就我而言,它不起作用。下面是我用于此函数的代码:

function PostData(){

    var validation=false;
    jQuery("#training_submit").prop('disabled', true);

    jQuery('#error_traff').hide();
    jQuery('#error_epost').hide();
    jQuery('#error_fname').hide();
    jQuery('#error_lname').hide();
    jQuery('#error_skola').hide();
    jQuery('#error_grade').hide();
    jQuery('#error_municipality').hide(); 

    var traff= jQuery("#training_traff").val().trim();
    var email= jQuery("#training_epost").val().trim();
    var firstname=jQuery("#training_fname").val().trim();
    var lastname= jQuery("#training_lname").val().trim();
    var phone= jQuery("#training_phone").val().trim();
    var school= jQuery("#training_skola").val().trim();
    var municipality = jQuery("#training_municipality").val().trim();
    var grade= jQuery("#training_grade").val().trim();
    var other= jQuery("#training_other").val().trim();

    if(traff =="") {
        jQuery('#error_traff').show();
        jQuery("#training_traff").focus(); 
    } else if(email =="") {
        jQuery('#error_epost').show();
        jQuery("#training_epost").focus(); 
    } else if(firstname =="") {
        jQuery('#error_fname').show();
        jQuery("#training_fname").focus();
    } else if(lastname =="") {
        jQuery('#error_lname').show();
        jQuery("#training_lname").focus();
    } else if(school =="") {
        jQuery('#error_skola').show();
        jQuery("#training_skola").focus();
    } else if(municipality =="") {
        jQuery('#error_municipality').show();
        jQuery("#training_municipality").focus();  
    } else if(grade =="") {
        jQuery('#error_grade').show();
        jQuery("#training_grade").focus();
    } else{
        jQuery('#loading').show();
        validation=true;
    }

    if(validation==true)
    {
        var user = {
        person_eMail: email,
        person_firstName:firstname,
        person_lastName: lastname,
        company_name: school,
        company_municipality:municipality,
        person_schoolYear: grade,
        person_position: "",
        project_name: "",
        Place: "",
        DeliveryLocation: "",
        person_phone: phone,
        Title: "",
        ReqDelivery: "",
        MeetingName: traff,
        OtherInfo: other,
        PreSchool: false,
        Elementary_Fk6: false,
        FK9: false,
        HighSchool_Other: false,
        Peephole: false,
            FormName:"Pedagogträffsintresse",
            RegisterDate: ""

        };

        jQuery.ajax({
            type: "POST",
            data: user,
            url: 'https://example.com/xxxx/xxx/',
            dataType: 'text',
            async: false,
            headers: {'Authorization': 'xxxxx'},
            success: function (result) {
                clearData(); 
                jQuery('#loading').hide();
                jQuery('#training_success').show();
                console.log(result);
            },
            error: function(error) {
                console.log(error);
                $("#training_submit").prop('disabled', false);
            }
        });        
    } else {
        jQuery("#training_submit").prop('disabled', false);
    }
}
请查看代码并帮助我解决此问题

谢谢

$('#maindivIdHERE').on('click', '.buttonClassHERE', function(){
$('#loading').show();
});

请将此代码插入您的代码上方。

您是否可以使代码缩进类似于可读代码?另一件事是。。。这个
微调器
显然是一个id为
正在加载的元素
。。。你有这样的元素吗?谁知道呢,你完全没有显示HTML代码缩进。请下次用更多的爱来编码。@@Ferrmolina,谢谢。我已经按照你的建议试过了,但没有按预期效果。请评论。