Function does not enter ajax success with jquery

0

I can not get ajax success with this function. The function works, that is, it calls the double click. The first alert is ok, but the second is not triggered.

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

    alert('Alô, tudo bem?');

    var obj = {};

    $('tr').each(function () {
        obj = {
            _nivel: $(this).find('td').eq(0).text, 
            _nome: $(this).find('td').eq(1).text, 
            _usuario: $(this).find('td').eq(2).text
        }
    })

    $.ajax({

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

Doing my tests, I saw that this is wrong:

$('tr').each(function () {
        obj = {
            _nivel: $(this).find('td').eq(0).text, 
            _nome: $(this).find('td').eq(1).text, 
            _usuario: $(this).find('td').eq(2).text
        }
    })
    
asked by anonymous 16.10.2014 / 20:38

2 answers

1

Use .text()

The dataType can be JSON without problems.

Your obj variable is a problem. It will always contain the data from the last line. Use:

var obj = [];
$('tr').each(function(index) {
   obj[index] = { ...... }
});
    
20.10.2014 / 15:08
0

Friend your problem is here:

 url: '/CadastroAcesso/CarregaDadosPagina',

You need to pass the complete url, for example:

 url: 'http://www.seusite.com.br/CadastroAcesso/CarregaDadosPagina',

Also make sure that the data type that is passed in the dataType

parameter is returned for this function.     
13.04.2016 / 21:24