jQuery function does not work

Asked

Viewed 365 times

-3

I’m doing a function with jQuery, but it doesn’t work, IE, it doesn’t reach my controller, someone could help me please follow the code:

var Aprovar = function () {
    $.ajax({
        url: 'GerenciaPassagem/AprovarPassagem',
        type: 'POST',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: JSON.stringify({ mes: $("#ListaPeriodo").val() }),
        success: function (data) {
            $("#tabFiltra").html(data);
            drawTable();
        },
        beforeSend: function () {
            $.blockUI({ message: '<img src="' + url + '/Content/ajax-loader.gif" alt="Aguardando..."/>' });
        },
        complete: function () {
            $.unblockUI();
        },
        error: function (a, b, c) {
            var x = a;
        }
    });
}

HTML

<input type="button" value="Aprovar" id="btAprovar" onclick="listaPassagens(); return false;" style="margin-left: 9px;" /> @*onclick="Aprovar(); return false;"*@
  • 5

    Your button does not call the function Aprovar, and yes listaPassagens.

  • Read the bfavaretto? comment can reply and if necessary join function code listaPassagens();

  • Add your Controller with this Actionresult

  • Has this post already been fixed? @user7566 ???

1 answer

3


If I understand correctly, what you want to do is call that function by clicking the correct button?

If yes the code will look like this:

change var Aprovar = function () {

for: function listaPassagens(){ /* Nome que você já utilizou */

On the button you’ll have to have it:

<intput type="button" onclick="javascript: listaPassagens();"

or add the line in your js and remove the calls from the button:

$("#btAprovar").click( function(){ listaPassagens() } );

I hope I’ve helped.

  • Your last line is incorrect, you can’t call listaPassagens

  • If you create the function as mentioned above: "Function listPassagens()" yes... I added a Function in the call because I did not test the code.

  • With your change yes, it works. Otherwise I guarantee that no.

  • Thanks for the fix @bfavaretto really hadn’t paid attention

  • Has this post already been fixed? @user7566 ???

  • Worked thanks

  • The function listaPassagens can be passed directly to the click, just to avoid creating another function: $("#btAprovar").click(listaPassagens); :)

Show 2 more comments

Browser other questions tagged

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