Get the value of a TD tag by jquery and send to method in Controller

1

How do I get the value of a tag when I double-click it and get that value and move to a method in my controller. The double click function is working.

$('#nmUsuario').on("dblclick", '.clique', function() {
    CarregaDados();
})

Where nmUsuario is the tbody of my table. My method CarregaDados(); is where I want to get the value of the clicked tag and pass it to the controller via json.

function CarregaDados() {

    $('.rowid').find('td').each(function () {
        var test = $(this).text();
        alert(test);
    })


    $.ajax({

        url: '/CadastroAcesso/CarregaDadosPagina',
        datatype: 'json',
        contentType: 'application/json;charset=utf-8',
        type: 'POST',
        data: JSON.stringify({ aqui não sei o que passar }),
        success: function (data) {
            alert('Alô, tudo bem?');
        },
        error: function (error) {
        }
    })
}

Where rowid is my <TR> , however, since I want to get only the clicked tag, does it make sense to do each? The code I made before ajax, does not enter the alert. I do not know the test value.

public JsonResult CarregaDadosPagina(string _nivel, string _nome, string _usuario)
        {
            RupturaEntities db = new RupturaEntities();

            //var result_carrega_pagina = db.

            return Json(new {  }, JsonRequestBehavior.AllowGet);
        }
    
asked by anonymous 23.10.2014 / 12:45

2 answers

1

Problem solved by another colleague:

$('#nmUsuario').on("dblclick", ".clique", function() {
   CarregaDados($(this).text());
});
function CarregaDados(ajaxParameter) {

     $.ajax({

        url: '/CadastroAcesso/CarregaDadosPagina',
        datatype: 'json',
        contentType: 'application/json;charset=utf-8',
        type: 'POST',
         data: { nome: ajaxParameter },
        success: function (data) {
            alert('Alô, tudo bem?');
        },
        error: function (error) {
            alert('Fail?');
        }
    })
}

Jsfiddle

    
23.10.2014 / 14:57
3

You can find out which td was clicked using "this" within the callback function:

$('table td').on("dblclick", '.clique', function() {
    alert($(this).text());
})

Another example with ajax:

$('table td').on("dblclick", '.clique', function() {
    var dados = {
        textoTd : $(this).text()
    };

    $.ajax({
        url: '/CadastroAcesso/CarregaDadosPagina',
        datatype: 'json',
        contentType: 'application/json;charset=utf-8',
        type: 'POST',
        data: dados,
        success: function (data) {
            alert('Alô, tudo bem?');
        },
        error: function (error) {
        }
    })
})
    
23.10.2014 / 14:26