2013-05-08 4 views
-1

У меня проблемы со сценарием. Я использую функцию jQuery.post внутри setTimout и возвращает TypeError: g.nodeName is undefined на Firebug. Вот мой сценарий:jQuery и setTimeout: TypeError: g.nodeName не определено

jQuery(function($) { 
var timer; 

    $("#tabela-orcamento .item .item-qtd .qtd-item").keyup(function() {  
     clearTimeout(timer); 

     timer = setTimeout(function() {   
      $.post("../../aj_orc.php?op=atualizaQtd", { 
       item: $(this).parents(".item").attr("data-item"), 
       qtd: $(this).val() 
      }, function(data) { 
       $("#retornos").html(data); 
      }); 
     },1000); 
    }); 
}); 

Что-то не так?

+0

спасибо, мне это помогло. –

ответ

4

Ваш бег в проблему, потому что внутри вашего таймаута относится к другому контексту, как вы думаете. Просто введите еще один that в качестве промежуточной переменной:

jQuery(function($) { 
    var timer; 

    $("#tabela-orcamento .item .item-qtd .qtd-item").keyup(function() {  
     clearTimeout(timer); 

     var $that = $(this); 
     timer = setTimeout(function() {   
      $.post("../../aj_orc.php?op=atualizaQtd", { 
       item: $that.parents(".item").attr("data-item"), 
       qtd: $that.val() 
      }, function(data) { 
       $("#retornos").html(data); 
      }); 
     },1000); 
    }); 
});