AJAX 요청이있을 때 함수를 호출하려고합니다. 난 그냥 버튼 아래에 주입 할 수 (있는 GetData의 함수가 호출) function1
이 실행해야하고, 응답을AJAX 응답을 HTML 페이지에 삽입하는 방법은 무엇입니까?
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.NextPage').click(function() {
$.ajax({
url: 'test.php',
data: {x: 1},
type: 'POST',
dataType: 'JSON',
success: function(response) {
// do not want any alerts or notifications here
}
});
});
});
</script>
</head>
<body>
<button type="button" class="NextPage">go to nextpage</button>
<?php
if (isset($_POST['x'])) {
if ($_POST['x'] == 1) {
function1();
}
}
function function1() {
// this is a sample of what im trying to do in this function
global $resultNUM;
global $recordsPerPage;
global $var;
global $i;
global $searchid;
if ($resultNUM > $recordsPerPage * i) {
$nexturl = "something";
$firstloop=false;
getdata($nexturl, $var,$firstloop);
$i++;
} else {
echo "end of results";
}
}
?>
</body>
이 지금까지 내 코드입니다.
if ($_POST["action"] == "function1")
function1();
그리고 당신의 AJAX 호출에서
가 다음을 수행하십시오 :
간단한 페이지를 원한다면'document.write (response);'를 사용해보십시오. 간단한 echo를보실 수 있습니다. – user1978142
@kevinabelita echo는 그냥 example.plz였습니다. 다시 한번 질문 해주세요. function1을 수정했습니다. – user3622910