<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
ajax사용하기 위해선 jquery 스크립 적어주기..
얘 안적어서 데이터 안나온다고 며칠 끙끙 거림ㅜ
ajax 기본 양식
<script type="text/javascript">
$(document).ready(function(){
$("#button").click(function(){
$.ajax({
url:"http://localhost:3000/getRecipeWeb",
type:"post",
data:{ "recipeName":"recipeName" },
success:function(json){
alert('success');
},
error:function(){
alert('error');
}
});
});
});
</script>
data:{}에서
int는 recipeSeq:$("#recipeSeq").val()
String은 "recipeName":"recipeName"
serialize()
data : $("#data").serialize() : 데이터를 묶어서 한번에 전달
data : { "animal" : animal , "food" : food , "merchandise" : merchandise } : serialize사용 안할시 다 적어줘야함
데이터 넣기
시퀀스 파라미터 가져오기!
시퀀스를 통해서 데이터를 가져올 경우 주소 끝에 시퀀스가 나온다.. 이것을 urlParams에 넣어 가져오기!
http://localhost:8090/Recipe/recipedetail.html?recipeSeq=20 (20이 시퀀스이자 파라미터로 넣을 숫자)
const url = new URL(location.href);
const urlParams = url.searchParams;
let recipeSeq = urlParams.get("recipeSeq");
'SpringBoot' 카테고리의 다른 글
[SpringBoot] SpringToolSuite (0) | 2022.03.23 |
---|---|
[SpringBoot] Android(Member) (0) | 2022.03.20 |
[SpringBoot] Android !Retrofit! (0) | 2022.03.20 |
[SpringBoot] 게시판 (0) | 2022.02.28 |
[SpringBoot] Front (0) | 2022.02.23 |
댓글