그래서 내가 이 작업을 수행하는 방법을 자바 스크립트에 함수를 호출하는 버튼 클릭 후 PHP 함수를 해고해야합니까? 나는이 작업을 수행해야하는 이유에 아주 명확하지 오전하지만 여기 간다
... 버튼을 클릭 핸들러에서
당신은 AJAX 호출을 만들고 싶어. 내가 jQuery를 사용하지만 당신이 원하는 모든 프레임 워크 또는 XMLHttpRequest 함수를 사용할 수 있습니다.
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
function ButtonClickHanlder(e) {
// Prevent the button from doing something it's normal functions(ie submit form if it is a submit)
e.preventDefault();
// Make AJAX Call
$.post("test.php", { call: "callMe" },
function(data){
alert("Data Loaded: " + data);
}
);
}
$(function(){
$('#clicker').click(ButtonClickHanlder);
});
</script>
</head>
<body>
<a id="clicker" href="#">test</a>
</body>
</html>
참조 : http://docs.jquery.com/Ajax
test.php 페이지
<?php
if(isset($_POST['call']) && $_POST['call'] == 'callMe') {
callMe();
}
function callMe() {
echo "I am a php function. You rang?";
}
?>