2012-09-17 4 views
0

스트림을 재생하는 사이트가 있습니다. 한 사람이 버튼을 누르면 서버에 AJAX 호출을 수행합니다.Ajax 사용 후 클릭 핸들러

<input type="submit" class="play" data-type="<?php echo $result_cameras[$i]["camera_type"]; ?>" data-hash="<?php echo $result_cameras[$i]["camera_hash"]; ?>" value="<?php echo $result_cameras[$i]["camera_name"]; ?>"> 

이렇게하면 사용자가 선택할 수있는 일련의 버튼이 인쇄됩니다. 이는 다음 코드에 의해 처리됩니다

<script> 
$(document).ready(function(){ 

$(".play").click(function(){ 
    var camerahash = $(this).data('hash'); 
    var cameratype = $(this).data('type'); 
    function doAjax(){ 
     $.ajax({ 
      url: 'index.php?option=streaming&task=playstream&id_hash=<?php echo $id_hash; ?>&camera_hash='+camerahash+'&format=raw', 
      success: function(data) { 
       if (data == 'Initializing...please wait') 
       { 
        $('#quote p').html(data); 
        setTimeout(doAjax, 2000); 
       } 
       else 
       { 
        if (cameratype == "WEBCAM" && data == 'Stream is ready...') 
        { 
         $('#quote p').html(data); 
         window.location = 'rtsp://<?php echo DEVSTREAMWEB; ?>/<?php echo $session_id;?>/'+camerahash; 
        } 
        else if (cameratype == "AXIS" && data == 'Stream is ready...') 
        { 
         $('#quote p').html(data); 
         window.location = 'rtsp://<?php echo DEVSTREAMIP; ?>/<?php echo $session_id;?>/'+camerahash; 
        } 
        else 
        { 
         $('#quote p').html(data); 
        } 

       } 

      } 
     }); 

    } 
    doAjax(); 
}); 
}); 
</script> 

서버는 Stream is ready... 같은 메시지를 반환합니다. 내 문제는 추가 버튼 클릭을 제외하고 모든 것이 잘 작동한다는 것입니다. 특히 성공을 거두었을 때 (동영상 재생) 다시 나가면 다른 버튼을 클릭하면 다른 메시지가 표시되지 않습니다. 마치 클릭 이벤트가 트리거되지 않은 것입니다. 응답하기 위해 클릭 핸들러에 뭔가를해야합니까?

답변

0

동적으로로드 된 단추에 대리자 이벤트를 사용합니다. 델리게이트 이벤트를 구현하려면 on() 메서드를 사용하십시오. .on()

구문 :

$(parent).on(eventName, target, handler); 
관련 문제