728x90
1. 자바스크립트 빈 문자열 검사 함수
function isEmpty(strIn)
{
if (strIn === undefined)
{
return true;
}
else if(strIn == null)
{
return true;
}
else if(strIn == "")
{
return true;
}
else
{
return false;
}
}
* 출처 : https://stackoverflow.com/questions/19592721/isempty-is-not-defined-error
isEmpty is not defined-error
I was getting an error as isEmpty is not defined .what i have to do .while alerting too it is not showing any alert. <!DOCTYPE html> <html> <head> ...
stackoverflow.com
2. 활용
function insertComment() {
var boardId = $('input[name=boardId]').val()
var content = document.getElementById("content").value;
if (isEmpty(content) == true) {
alert('댓글을 입력해주세요.')
return false;
} else {
$.ajax({
type: 'POST',
url: '/board/comment/write',
data: {
boardId: boardId,
content: content
},
success: function (response) {
getComments()
console.log("insert success")
},
error: function (response) {
console.log("insertComment error : " + response)
},
})
}
}
- 댓글 추가 ajax 코드
- 댓글 내용 없이 작성버튼을 클릭하면 경고문을 띄우고 리턴.
'Web > JAVASCRIPT' 카테고리의 다른 글
[Jquery] 체크박스 값 배열에 담기 (0) | 2022.01.06 |
---|---|
[JavaScript] 날짜 포맷 변경 라이브러리 (0) | 2022.01.06 |
[Jquery] 특정 태그 뒤에 새로운 태그 생성 (0) | 2022.01.04 |
[Jquery] 이름으로 태그 불러오기 & 태그 숨기기 (0) | 2022.01.04 |
[JavaScript] 확인창 및 팝업창 띄우기 (0) | 2022.01.03 |