2022 / 10 / 14 - 2주차 study

김형준 Kim Hyeong Jun·2022년 10월 14일
0

JQuery

id -> #으로 호출

$('#id')

split, includes

string.slpit(',')

string(문자열)을 , 기준으로 리스트 형식으로 분리.

ex)
let txt = '김,이,박'
let list = txt.split(',')
console.log(list)
[김, 이, 박]

string.includes('@')

string(문자열) 안에 @가 포함되어 있으면 true,
포함되어 있지 않으면 false 출력

ex)
let txt = 'hjun@naver.com'
let mail = txt.includes('@')
console.log(mail)
true

function을 통해 html 삽입

html을 벡틱 을 통해 정의 하고,
append를 이용하여 삽입.

AJAX

$.ajax({
type: "GET",
url: "여기에URL을입력",
data: {},
success: function(response){
console.log(response)
}
})

$.ajax({
type: "GET", // GET 방식으로 요청한다.
url: "http://spartacodingclub.shop/sparta_api/seoulair",
data: {}, // 요청하면서 함께 줄 데이터 (GET 요청시엔 비워두세요)
success: function(response){ // 서버에서 준 결과를 response라는 변수에 담음
console.log(response) // 서버에서 준 결과를 이용해서 나머지 코드를 작성
}
})

url 바꾸는 ajax

ex)
$('#img-rtan').attr('src',url)

text 바꾸는 ajax

ex)
$('#text-rtan').text(msg)

profile
I want be a developer🙂

0개의 댓글