2012-01-03 2 views
1

데이터를 사용하려고 :이 코드가()

$('.solicitud_amistad').click(function(){ 
    var aux = $(this); 
    console.log($(this)); 
    console.log($(this).data('receptor')); 
    $.post('amistad/nueva' , {id_receptor:$(this).data('receptor')}, 
     function(response){ 
      aux.replaceWith(response) 
     } 
    ); 
}); 

을 나는이 출력을 받고 있어요 :

<a class="solicitud_amistad" data-receptor="4">Enviar solicitud de amistad</a> 
undefined 

내가 대신 undefined4을 기대했다.

+0

당신의보기가 저를 위해 작동합니다. http://jsfiddle.net/M7JjF/ –

+0

.data ('수용체')를 사용하고 있지만 요소의 키는 데이터 수용체입니까? – osoner

+0

도 나에게 효과적이다. http://jsfiddle.net/qKuZq/ - jquery의 어떤 버전을 사용하고 있습니까? – swatkins

답변

0

시도 :

jQuery.data(this, 'receptor'); 

그건 당신이 데이터를 올바르게 설정 실패 후 작동하지 않습니다 당신이 수용체라는 키에 대한 데이터를 저장할 위치를 게시 할 필요가됩니다.