개발하는 루루언니

ajax : get 요청하기 본문

컴퓨터 정보/javascript

ajax : get 요청하기

혜닝혜루 2022. 12. 9. 21:49
728x90
반응형
 $.get('https://codingapple1.github.io/hello.txt')
 .done(function(data){
  console.log(data)
 })
 .fail(function(){
  console.log('실패함')
 })

 

1. $.get(' url ' )

.done(function(data){

 파라미터로 data를 받아올 수 있다.

})

 

콘솔창에 출력하면 해당 값에 대한 정보가 나온다.

 

2. fail(function(){

 " fail 은 에러가  날경우 디버깅을  알 수 있다 " 

})


다른예제

 $.get('https://codingapple1.github.io/price.json')
 .done(function(data){
  console.log(data)
 })
 .fail(function(){
  console.log('실패함')
 })

다른 url로 get 요청을 했을때 만약 

 

{ price : 5000 } 이렇게 오브젝트 형으로 되어 있다

그럼 5000만 꺼내오고 싶다면?

 

console.log(data.price ) 이렇게하면 값만 꺼내져 나온다. ^^

728x90