javascript利用setInterval进行轮询操作一例

<script  language='javascript'>
					var intervalID = null;
					//点击‘扫描’按钮
					function saveScanInfo(){
						var url = "/lhys/scanFile.do";
						$.ajax({
							url:url,
							type:"POST",
							success:function(data){
								var millisec = 1000*1;
								intervalID = setInterval(queryScanFile,millisec);//setInterval()方法第一个参数为js方法名或者js方法,第二个参数为循环的时间间隔
							}
						});
					}
					
					//查询数据库中对应记录是否可以扫描
					function queryScanFile(){
						var url = "/lhys/queryScanFile.do";
						$.ajax({
							url:url,
							data:{},
							type:"POST",
							dataType:"text",
							beforeSend:function(){
								$('#scaningImg').show();
							},
							success:function(data, textStatus, jqXHR){
								//alert(data + "," + textStatus + "," + jqXHR);
								//var filePath = "H:/扫瞄管理程序/ScanImages/PC00120140219111832.PDF";
								if(data == 'success'){
									window.clearInterval(intervalID);
									$('#scaningImg').hide();
									alert("扫描成功!请点击【上传】按钮上传资料...");
								}else if(data == 'failed'){//failed scaning success
									alert("扫描文件失败!请重新扫描文件...");
									$('#scaningImg').hide();
								}else if(data == 'scaning'){
									queryScanFile();
								}
							}
						});
					}
					
								
				</script>

你可能感兴趣的:(javascript利用setInterval进行轮询操作一例)