Failed to call function with Javascript parameter

Asked

Viewed 54 times

0

I have the following function:

function show(msg, el){
    if(msg.alertType == 0){
    resetForm(el);
    setTimeout(function(){                  
        $('#show-toast').removeClass('toast-show');
        $('#show-toast .td.result .msg').remove();
    }, 5000);
    }else if(msg.alertType == 1){

    }etc..
}

function resetForm(form){
    if(form.length){
        form.trigger('reset');
        $(form).find("input[type='text']").each(function( index ) {
            if (!$(this).val())
                $(this).parent().removeClass('is-dirty , is-invalid');
        });
        $('.preview').find('img').attr('src', '#');
    }
}

if($('#form-blog').length){
    $('#enviar-post').click(function(e) {           
        var dados = new FormData($("#form-blog")[0]);
        var form = '#form-cursos';
        dados.append('action', 'insert-blog');

        $.ajax({
            url: 'database/actions.php',
            type: 'POST',               
            data: dados,
            processData: false,
            contentType: false
        })
        .done(function(rtv) {
            var data = JSON.parse(rtv);
            show(data, form);
            console.log("success");
        })
        .fail(function() {
            console.log("error");
        }).always(function(rtv) {
            $('#mdl-console').append(rtv);
        });
        return false;
    });
}

however the function resetForm(el) of error, says that form is undefined

1 answer

5


maybe

var form = '#form-cursos';

should be:

var form = $('#form-cursos');

  • curious, tried it a thousand times and it didn’t work, thank you!

  • @Hebertdelima, all right, we’ve all been through some syntactic mistakes before ; )

  • @Hebertdelima resolved?

  • yes solved ; )

Browser other questions tagged

You are not signed in. Login or sign up in order to post.