0
저는 Ajax 예제를보고 PHP에 변수를 보내고 다른 변수를 돌려 보았습니다. 이것은 다른 페이지 (how to get variables from php using AJAX)에서 왔지만 무언가가 나를 위해 작동하지 않는 것 같습니다. 나는 오류를 범하지 않으며, 아무런 행동도 일어나지 않습니다. 내 목표는 단순히 일부 데이터를 PHP 페이지에 게시하고 변수를 가져와 다른 DIV에 저장하는 것입니다.Ajax 쿼리가 작동하지 않습니다.
htmlpage.html
<html>
<head>
<script>
$(document).ready(function() {
$("#ajaxButton").click(function() {
$.ajax({
url:'phppage.php',
data:{username: $('#username').val()},
type:'POST',
success: function(data) {
$('#result').html(data);
}
});
});
});
</script>
</head>
<body>
<input type="text" name="username" id="username"/>
<input type="button" value="Find" id="ajaxButton"/>
<div id="result">This should change on click</div>
</body>
</html>
phppage.php
<?php
$_POST['username'];
$username = $_POST['username'];
$result = '<div class="result">' .$username. "</div>";
echo $result;
?>
'는 정의되지 않았습니다. (당신은 jQuery를 포함하는 것을 잊었습니다.) 브라우저 콘솔에서 오류를 확인하십시오. 팝업에 표시되지 않는다고해서 오류가 없음을 의미하지는 않습니다. – David
'나는 오류가 발생하지 않습니다 .' - 그 경우 올바른 장소를보고 있지 않습니다. –
넣기 -> ""=>
tags –