2023~/js,jquery

$.get(), $.post(), $.getJSON()

yanii 2023. 5. 20. 23:00

$.get() : ajax get요청할 때 사용, 서버에서 데이터를 가져올 때 사용

$.get(url, [data], [success], [error]);

$.get('경로', function(response){
  //response는 서버의 응답
});

 

 

$.post() : ajax post요청할 때 사용, 서버에 데이터를 전송할 때 사용

$.post(url, data, [success], [error]);

$.post('경로', {
  name: 'kim',
  email: 'kim@example.com'
}, function(response) {
  // response는 서버의 응답
});

 

 

$.getJSON() : url에서 json 데이터를 가져오는 데 사용

$.getJSON("경로", function(data){
	// data는 서버에서 가져온 JSON 데이터
});