2012-06-09 4 views
3

jquery 함께 var 보내려고 할 때 아약스 php받지 못하고 이유를 모르겠습니다.어떻게 jquery var PHP로 보낼 수 있습니까?

이 내 스크립트입니다

function showHiddenUserInfoPanel(id){ 
$(document).ready(function(){ 
    $('#admin-resume').fadeToggle('slow', 'linear', function(){ 
     $.ajax({ 
      async: true, 
      type: "POST", 
      dataType: "html", 
      contentType: "application/x-www-form-urlencoded", 
      data: "userid="+id, // Also I tried with : data: {userid: id}, 
      url: "user-profile.php", 
      success: function(){ 
       $('#info-user').fadeToggle('slow', 'linear'); 
       alert(id); // I receive the correct id value 
      } 
     }); 
    }); 
}); 

그리고 이것은 내 사용자 profile.php입니다 :

<div id="activity_stats"> 
    <h3>Viendo el perfil de <?php echo $_POST["userid"]; ?></h3> 
</div> 

아무도 나를 도울 수 수 있습니까?

감사합니다 :)

+0

Fiddler를 사용하여 HTTP 요청을 추적하고 올바른지 확인하십시오 ... – CodeZombie

+0

왜 함수 안에'$ (document) .ready() '를 사용하고 있습니까? 함수를 호출하기 전에 문서가 준비 될 때까지 기다리고 싶지만 함수 자체 내에서 기대 한대로 수행하지 않을 수 있습니다. 그것은 당신이 실제로 그 기능에서 무엇인가를하지 않고 있음을 의미합니다. 당신은 단지 사건에 구속력이 있습니다. – David

+0

@David DOM이 이미 준비된 경우 함수가 즉시 호출됩니다. – lonesomeday

답변

7

은 그냥 날인가, 아니면 당신은 모든 응답을 사용하지 않는?

$.ajax({ 
    success: function(){ 
    $('#info-user').fadeToggle('slow', 'linear'); 
    } 
}); 

익명 success 함수는 모든 응답을 무시합니다. 귀하의 #info-user은 빈 요소 여야하고 귀하는 시각적 피드백을 얻지 못할 것으로 생각됩니다.

예는 수 :

$.ajax({ 
    success: function(response){ 
    $('#info-user').html(response).fadeToggle('slow', 'linear'); 
    } 
}); 

다른 대안은 .load()를 사용 할 수있다.

+0

더 많은 정보를 추가하기 위해 jQuery'.load()'함수가 그의 필요에 유용 할 수도 있습니다 : http://api.jquery.com/load/ – David

+0

@David, 제가 추가했습니다;) – Alexander

+0

@Alexander로드()는 ajax()와 동일하지만 데이터, URL 및 콜백 만 필요합니까? 감사합니다 :) – jask

관련 문제