I cant update a div after keypress using ajax
hello, I have a problem when I am trying to update a div after to save a record in my DB, what I am doing is to save a record and then to print in another div.
here is my code:
- $('input.txtcomentario').keypress(function(e) {
- if (e.keyCode === 13) {
- var idp = $(this).closest('.dvpublicacion').find('input.hdidpub').attr('value');
- var comentario = $(this).attr('value');
- $(this).val('');
- if (comentario.length > 0) {
- $.ajax({
- type: 'POST',
- url: "interaction/savecomment.php",
- data: 'idp=' + idp +
- '&comentario=' + comentario,
- success: function(data) {
- $.ajax({
- type: 'GET',
- url: "interaction/listcomments.php' ?>",
- data: 'idp=' + idp,
- success: function(data1) {
- $(this).closest('.dvpublicacion').find('.dvcomentariospub').html(data1);//This does not work
- }
- });
- }
- });
- }
- }
- });
But something strange occurs, when I print anything on the div outside of the second ajax, it works.
- $('input.txtcomentario').keypress(function(e) {
- if (e.keyCode === 13) {
- var idp = $(this).closest('.dvpublicacion').find('input.hdidpub').attr('value');
- var comentario = $(this).attr('value');
- $(this).val('');
- if (comentario.length > 0) {
- $.ajax({
- type: 'POST',
- url: "interaction/savecomment.php",
- data: 'idp=' + idp +
- '&comentario=' + comentario,
- success: function(data) {
- $.ajax({
- type: 'GET',
- url: "interaction/listcomments.php' ?>",
- data: 'idp=' + idp,
- success: function(data1) {
-
- }
- });
- $(this).closest('.dvpublicacion').find('.dvcomentariospub').html('anything');// This works
- }
- });
- }
- }
- });
I can find the mistake, please help me.