Uncaught Referenceerror: method is not defined

Asked

Viewed 456 times

0

I’m calling a method to convert my ajax request to a readable date, but I keep getting the message that the function has not been set, I don’t understand why, since it is literally the function just above the one you are using

//converte o valor recebido em um objeto do tipo date em js
convertToJavaScriptDate: function (value) {
    var pattern = /Date\(([^)]+)\)/;
    var results = pattern.exec(value);
    var dt = new Date(parseFloat(results[1]));
    return dt.getDate() + "/" + (dt.getMonth() + 1) + "/" + dt.getFullYear();
},


CarregaInfoComplementares: function (id, obj) {
    var Id = id;
    var tr = obj;
    $('.selectedRow').removeClass('selectedRow');
    $(obj).closest('tr').children().each(function () {
        $(this).addClass('selectedRow');
    });
    dados_entrada = "{'Id':'" + Id + "'}"
    $.ajax({
        type: "POST",
        url: "Pacote.aspx/CarregaInfoComplementares",
        data: dados_entrada,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () {
        },
        success: function (data, msg) {
            var row = $.parseJSON(data.d).dt[0];
            var datInicioValidade = convertToJavaScriptDate(row['DAT_INICIO_VALIDADE']);
            //mais codigo
       },
    });
},

I get the following error in the browser console: Uncaught Referenceerror: convertToJavaScriptDate is not defined

1 answer

2


Just to better understand, is all this code inside an object? If it is inside an object the correct to call its function would be so:

objectName.convertToJavaScriptDate()

That one ReferenceError probably must be happening because its function exists only within that object where it was declared.

  • Thanks! I didn’t know I needed to say the name of the object being that it was already inside itself...

Browser other questions tagged

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