실수로부터 배우려는 신참 코더. :)
세 개의 파일 (jquery.js, php.php 및 html.html)이 있습니다.
mySQL 데이터베이스 이름에서 정보를 가져 오려고합니다 trial1
. 라는 테이블이 하나만 Score_Sheet
있습니다.
아래는 html.html의 코드입니다.
<!DOCTYPE html>
<html>
<head>
<script type="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src= "jquery.js" type = "text/javascript"></script>
</head>
<body>
<button id = "button"> Click to see value from SQL table</button>
<div id= "content"></div>
</body>
<html>
아래는 php.php의 코드입니다.
$link = mysqli_connect("localhost","root","","trial1");
$query = "SELECT * FROM Score_Sheet";
$show = mysqli_query($link, $query) or die ("Error");
echo "<table><tr><td>ID</td><td>UserID</td><td>Score</td></tr>";
while ($row = mysqli_fetch_array($show)){
echo "<tr><td>" . $row['ID'] . "</td><td>" . $row['UserID'] . "</td><td>" . $row['Score'] . "</td></tr>";
}
echo "</table>";
}
아래는 jquery.js의 코드입니다.
$(document).ready(function(){
$("#button").click(function(){
function show_all(){
$.ajax({
type = "POST",
url = "php.php",
success: function (data){
$("#content").html(data);
}
});
}
// show_all();
});
});
오늘 좋은 것을 배웠습니다. 여러분 감사합니다. 어떤 오류가 발생하는지 확인하기 위해 개발자 도구를 사용해야했습니다. Error was ReferenceError : $ is not defined. 그런 다음 오류를 검색하고이 인라인 링크 포럼을 사용 하여 수정했습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다