ajax 중복체크 질문
본문
test1.php
<span class="teach_type" data-idx="2911">test1</span>
<span class="teach_type" data-idx="2912">test2</span>
<span class="teach_type" data-idx="2912">test3</span>
test2.php
<script type="text/javascript">
$(".teach_c").click(function(){
tuid = $(this).attr('data-idx');
$.ajax({
url: "/ajax/teach.php",
type: "post",
dataType: "json",
data:{uid:tuid},
success: function(data){
if(opener.$('.teach_type').attr('data-idx') == tuid){
alert('이미 추가되어있습니다.');
} else {
opener.$('.teach_name').append(data.area);
}
}
})
return false;
});
</script>
db에 넣지않고 체크를 하려고하고있는데요
ajax success하면 append로
<span class="teach_type" data-idx="2911">test1</span>
<span class="teach_type" data-idx="2912">test2</span>
<span class="teach_type" data-idx="2912">test3</span>
하나하나씩 추가가됩니다.
근데 data-idx가 같은값이면 append가 되지않게하려고합니다..
도와주세요.ㅜ
답변 1
if($(".teach_type[data-odx="+tuid+"]", opener.document).size() > 0){
alert(
'이미 추가되어있습니다.'
);
}else{
$(
'.teach_name',
opener.document).append(data.area);
}
이렇게 처리해보세요.
답변을 작성하시기 전에 로그인 해주세요.