get text select and send form jquery

0

I made this function to send with jquery via post and I have to get the value and the text of the select and another 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_calling tbm, plus the text of the select and the link that is an input type text are not going to get the NaN value by firebug, I do not know what else to do.

    
asked by anonymous 17.03.2016 / 06:24

1 answer

4

opeta,

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

Test, assign a string to a variable and execute the expression +variavel , the return will be NaN .

Then for your code to work, just remove + :

 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;
    
17.03.2016 / 09:36