click handler after using Ajax
Posted
by
Tom
on Stack Overflow
See other posts from Stack Overflow
or by Tom
Published on 2012-09-17T03:34:16Z
Indexed on
2012/09/17
3:37 UTC
Read the original article
Hit count: 152
jQuery
I have a site that plays a stream. I perform an AJAX call to the server once a person presses a button.
<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"]; ?>">
This prints out a bunch of buttons that the user can select. This is processed by the following code:
<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>
The server returns the messages such as Stream is ready...
. My problem is that everything is working great except on additional button clicks. Specifically when they get success (video plays) and they exit back out, they don't get any other messages if they click another button. It is as if the click event is not triggered. Do I need to be doing something to the click handler to respond?
© Stack Overflow or respective owner