ajax this 질문드립니다. 채택완료
안녕하세요.
jquery 실행시
녹색 $(this).addClass('u_cbox_btn_recomm_on');
위치에 있으면 정상적으로 실행되는데
ajax를 처리하고 결과값에 똑같은 문장을 적으면
$(this).addClass('u_cbox_btn_recomm_on');
동작이 안되네요
ajax 동작후 $(this) 가 작동되게 할려면 변수를 따로 넘겨줘야 되나요?
감사합니다.
$(document).on('click','.u_cbox_btn_recomm',function(e){ var data_param = $(this).attr("data-param"); var commentNo = data_param.match(/commentNo:'(.*?)'/)[1]; var objectId = data_param.match(/objectId:'(.*?)'/)[1].split("_"); var series_id = objectId[0]; var no = objectId[1];
$(this).addClass('u_cbox_btn_recomm_on');
jQuery.ajax({ url: "webtoon_comment_mobile_json.php", type: "GET", timeout: 10000, cache: false, dataType : 'json', data: { platformType: 'COMMENT_RECOMM', series_id: series_id, no: no, uid: commentNo }, success: function(oResult) { var result = oResult.result; recomm_cnt = result.recomm_cnt;
if(result.code == 'S1') { $("#u_cbox_cnt_recomm_" + commentNo).text(recomm_cnt);
if(result.recomm_code == 'Y') { $(this).addClass('u_cbox_btn_recomm_on'); } else { $(this).removeClass('u_cbox_btn_recomm_on'); } } else if(result.code == 'E1') { alert(result.msg); } }, error: function() { alert("컨텐츠 목록을 불러오는 중 오류가 발생하였습니다. 다시 시도해 주세요2.") } }) });
답변을 작성하려면 로그인이 필요합니다.
로그인
감사합니다.