2013-08-18 4 views
-3

PHP 변수와 PHP에서 jQuery로 jQuery 변수를 전달하는 방법이 있습니까? jQuery를 사용하여 div (PHP로 생성 된 ID)의 ID를 가져 와서 해당 값을 변수에 제공하려고합니다. jQuery를에PHP로 jQuery 변수

+0

예, AJAX를 배울 예 (인 그리고 아마도 jquery ajax) –

+0

아약스를 봐 ... –

+0

문자 그대로 _ 수천 개의 문자가 있습니다. 이 주제에 대한 토론. 사이드 바의 관련 섹션에 나열된 것을 시작으로 살펴보십시오. http://stackoverflow.com/search?q=%5Bphp%5D+pass+javascript+variable+to+php –

답변

2

PHP : PHP에

<script type="text/javascript"> 
    jQuery(function($){ 
     $('#<?php echo $elementId; ?>').hide(); 
    }); 
</script> 

jQuery를 :

<script type="text/javascript"> 
    jQuery(function($){ 
     $.post('page.php', { var: 'value' }).done(function(data){ 
      // Do something 
     }); 
    }); 
</script> 
-2

당신이 게시물에 아약스를 사용하거나 여기 를 얻을 수는

//Javascript file 
$("input[type=checkbox]").click(function() { 
    $.post('my_ajax_receiver.php', 'val=' + $(this).val(), function (response) { 
     alert(response); 
    }); 
}); 

//PHP file ajax_remote.php 
<?php 
    $value = $_POST['val']; 
    echo "I got your value! $value"; 
?> 
+1

이것은 http://stackoverflow.com/a/5202083/1935077 –

+0

의 복사본 인 것 같습니다 이미 도움이되는 답변이있는 경우 , 그것을 복제하는 것이 아니라 링크하는 것이 가장 좋습니다. – halfer