私は、チェックボックスがオンになっている場合自動AJAXコールを停止する方法は?
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
Auto-ON
<input id="inp" type="checkbox" data-toggle="toggle" />
<div id="out"></div>
<script>
$('#inp').change(function(){
if (this.checked) {
setInterval(function(){
$.ajax({
url: 'http://dev.markitondemand.com/MODApis/Api/v2/Quote/jsonp?symbol=AAPL',
dataType: 'jsonp',
success: function(results) {
$("#out").append(results.Status + "<br />");
}
});
},5000);
}
});
</script>
</body>
</html>
は、私は5秒ごと用のAJAX呼び出しをしたい、APIに以下のAJAX呼び出しを持っています。チェックボックスがオフの場合、AJAXコールは停止する必要があります。私はここで何が欠けていますか? http://jsbin.com/quqazofesu/edit?html,output