채택완료

ajax 중복체크 질문

2017-07-03 (월) 16:26:45 9,057

test1.php

Copy
<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

Copy
<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개 / 댓글 1개

채택된 답변
+20 포인트

if($(".teach_type[data-odx="+tuid+"]", opener.document).size() > 0){

alert('이미 추가되어있습니다.'); 

}else{

$('.teach_name', opener.document).append(data.area);

}

이렇게 처리해보세요.

답변에 대한 댓글 1개

감사합니다..ㅠㅠㅠㅠ정말너무너무감사해요

답변을 작성하려면 로그인이 필요합니다.