pick up select text and send jquery form

Asked

Viewed 6,904 times

2

i made this function to send with jquery via post and have to get the value and text of select and one more value of an input type text. Follow the code below

    function SalvarRegistro(){
    $(this).ready(function(){
        var cursodisciplina_id = $("#disciplina option:selected").val();
        var descricao = $("#disciplina option:selected").text();
        var link = $("#link").val();
        var usuario_lancamento = $("#usuario_lancamento").val();
        var adicionar = 1;

        $.ajax({
            type: "POST",
            dataType: "json",
            url: "cursodisciplinaemena_acao.php",
            data: {cursodisciplina_id: +cursodisciplina_id, descricao: +descricao, link: +link, usuario_lancamento: +usuario_lancamento, adicionar: +adicionar},
            success: function(data) {
                    alert(data[0].msg);
            },
            failure: function() {
            alert("Ocorreu um erro, tente novamente!");
            }
        });
    });
    return true;
}

the cursodisciplina_id is going and the user tbm.

  • opeta, would share the HTML code as well?

  • What is the criterion that people are using to negatively, the person who did it could post the reason here? It’s a completely valid question.

1 answer

6


opeta,

I ran some tests here and I think I figured out the problem. If you notice, only your values of the kind String are not being sent. This is because you are using the +descricao instead of descricao.

Run a test, assign a string to a variable and run the expression +variavel, the return will be NaN.

So for your code to work, just remove the +:

 function SalvarRegistro(){
    $(this).ready(function(){
        var cursodisciplina_id = $("#disciplina option:selected").val();
        var descricao = $("#disciplina option:selected").text();
        var link = $("#link").val();
        var usuario_lancamento = $("#usuario_lancamento").val();
        var adicionar = 1;

        $.ajax({
            type: "POST",
            dataType: "json",
            url: "cursodisciplinaemena_acao.php",
            data: {cursodisciplina_id: cursodisciplina_id, descricao: descricao, link: link, usuario_lancamento: usuario_lancamento, adicionar: adicionar},
            success: function(data) {
                    alert(data[0].msg);
            },
            failure: function() {
            alert("Ocorreu um erro, tente novamente!");
            }
        });
});
return true;
  • Putz killed me I was already 1 hour trying to understand why only strings were not sent vlwww.

  • the merit of curiosity, because you were using the +?

Browser other questions tagged

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