jQuery and setInterval for HotFolder
I would like to create an hotfolder. A Hotfolder is a folder when a file was upload on, an application works. So I would like in my webpage check this folder in ajax. On click button, jQuery tell a php file (this PHP check folder). When a file is upload on the folder, jQuery tell me. I would like to stop the checking when PHP find a file.
My jQuery code :
<script type="text/javascript">
$(document).ready(function(){
$("#strap_signup").click(function(){
var refreshId = setInterval(function() {
$("#responsecontainer").load('file_check.php');
}, 1000);
});
});
</script>
My PHP Code :
<?php
$ftp_user_name="XXXX";
$ftp_user_pass="XXXX";
$destination_file="/Folder/in";
$conn_id = ftp_connect("XXXX");
$login_result = ftp_login($conn_id, "$ftp_user_name", "$ftp_user_pass");
$contents = ftp_nlist($conn_id, $destination_file);
$om = count($contents);
if($om!="0") echo "File is in";
?>
This is work, but when php find the file, jQuery continue to check. I would like to Stop It.
Something like this :
"if($("#responsecontainer")=="File is in"){window.clearInterval(refreshId);}"
More, my application take the file in the folder "in", works and put in the folder "out".
So I would like to check "IN",开发者_如何转开发 if file is dectected, check "OUT" to control the good job.
Thanks for yours help
Nearly, you dont need window.clearInterval get rid of the window bit and just have:
clearInterval(refreshId)
精彩评论