$(document).ready(function () { $("#blink").on('click', function () { console.log('click', '#blink') let url = 'http://192.168.0.116/cgi-bin/test.cgi'; let postData = { action: 'blink' } $.ajax({ type: 'POST', url: url, data: postData, dataType: "json", success: function (res) { if (res.success) { data = res.content } else { alert(res.message) } }, error: function (res) { } }) }) $("#logout").on('click', function () { sessionStorage.clear(); window.location.href='login.html' }) }) $(function () { var data = sessionStorage.getItem('state'); if (data != 'logined') { if (window.location.href.indexOf('login') != -1) { //login page console.log('bbbb') } else { window.location.href = 'login.html' } } })