MySQL
[eclipse] ajax사용해서 DB insert하기
by 10월의끝
2022. 8. 30.
//(insert) ajax.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script
src="https://code.jquery.com/jquery-3.6.0.js"
integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk="
crossorigin="anonymous"></script>
<script>
function to_ajax() {
var qstr = $("form[name='testForm']").serialize();
//alert(qstr);
$.ajax({
type: "post",
url: "insert.jsp",
data: qstr,
dataType: "text",
error: function(xhr, status, error) {
alert(error);
},
success: function(data) {
alert("입력 성공");
$("#name").val("");
$("#phone").val("");
$("#address").val("");
}
});
//alert("!!!");
}
</script>
</head>
<body>
<form name="testForm" id="testForm">
<table border="1">
<th>이름</th>
<th>핸드폰</th>
<th>주소</th>
<tr>
<td align="center" width="100" height="30"><input type="text" name="name" id="name"></td>
<td align="center" width="200" height="30"><input type="text" name="phone" id="phone"></td>
<td align="center" width="230" height="30"><input type="text" name="address" id="address"></td>
</tr>
</table>
</form>
<button onclick="to_ajax()">등록</button>
</body>
</html>
[mysql] 비주얼스튜디오 사용해서 ajax만들고 jsp로 DB insert하기.txt
0.00MB