Implementation and closing of the js timer of the jsp page (without jumping the page)

direct online code
<script type="text/javascript">
		var timename = null;
		function show1(){
			timename=setInterval(function cj(){
					$.ajax({
		        type: "GET",
		        url: "/opsmanager/server/diary",
		        success:function(json){
		        	console.log(json);
		        	$("#textareaid").val(json);
		        },
				error:function(){
					clearInterval(timename);
		         }
		   });},100);
		}
	function show2(){
		clearInterval(timename);
	}
</script>
</head>
<body>
<div style="padding:15px 25px;width:1200px;height: 830px;background-color: white;">
	<form>
			<input type="button" onclick="show1()" value="查询">
			<input type="button" onclick="show2()" value="停止">
		<fieldset>
			<legend>Configuration file modification</legend>
			<div style="float: left;">
				<textarea rows="20" cols="100" name="textareaid" id="textareaid">
		</textarea>
			</div>
		</fieldset>
	</form>
Set a button to turn the timer on and off
timename=setInterval(function a(){}, 1000) The front a is the program to be executed periodically, the latter 1000 is how often to execute it, and show2() is the stop ding
timer

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325592424&siteId=291194637