Change the value of jquery input to a posting system

Asked

Viewed 63 times

0

I got this little engine AJAX, I’m using jQuery, this code is for a posting system, but it’s not working.

The logic is to register posts with form using 2 buttons to send (Submit). One is to register only and the other is to register and publish the post. It will be saved in the field status the input that will be with value 0 and when you publish and register the attribute will be changed value for 1.

   //publicar e publicar e atualizar
    var button = $('.cadPub');
    var buttonCad = $('.cad');
    var cadastro = $('.formDados');//formulario
    cadastro.submit( function(){
        if(button){
            button.click(function(){
                $('.status').each(function(){
                    var input = $(this);
                    input .val(1);
                });
            });
        }else{
            $('.status').each(function(){
                var input = $(this);
                input .val(0);
            });
        }

    //CADASTRO
    if(button || buttonCad) {
        var id = $(this).attr('id');
        var cap = $(this).attr('data-controller');

        $.ajax({
            url: BASE + cap,
            data: {id: id},
            type: "POST",
            dataType: 'json',
            beforeSend: function (data) {
                $.each(alerts, function (key, value) {
                    $('.alert').removeClass(value);
                });
            },
            success: function (data) {
                if (data.retorno) {
                    $('.alerta').addClass(data.retorno[0]);
                    $('.icones').addClass(data.retorno[1]);//icone tem que passar no indice 1
                    $('.titulo').html(data.retorno[2]);//Titulo no indice 2
                    $('.result').html(data.retorno[3]);//Mensagem de retorno no indice 3
                }
            }
        });
    }
    return false;
});
  • the above code was outside the source code formatting. Admin can edit for me I don’t know how to use this editor much.

  • Open your eye, leather singing in Chico also sings in Francisco :D - edited question!! And reissued by Valdeir Psr

  • I think it would be interesting to post the HTML part involved in the question. It would facilitate the work of want to do tests.

  • HTML would import it would be the status ]field which is simple only an input with name ="status" value="0" and the 2 submits buttons register and publish. with encapsulated classes Cad and cadPub

  • This variable alerts in $.each(alerts, function (key, value) { comes from where?

  • this is the msg of sucess but this certain what I wanted is to submit the form of 2 ways a with each button and the Cad and the other Cad and publish

Show 1 more comment
No answers

Browser other questions tagged

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