您好,需要帮助才能在html中运行以下php。
function runMyFunction(){
$_SESSION["identificate"] = 'no';
session_destroy();
header('Location: Login.html');
}
---------------------------------------------------------
<div id="foo">
<button type="button" onclick="runMyFunction()">Logout
</button>
</div>
谢谢
您应该ajax
在的帮助下执行呼叫jQuery
。
我们可以使用简写方法.post
直接发出发布请求。
首先将php
代码放在一个单独的文件中,称为logout.php
logout.php
function runMyFunction(){
$_SESSION["identificate"] = 'no';
session_destroy();
//header('Location: Login.html'); we will move the redirect to the success handler of the ajax call
}
//call the function
runMyFunction();
然后在中html
,添加jquery
并添加script
如下所示的代码块
<script type="text/javascript">
$(function() {
$("#foo button").click(function(){
$.post( "logout.php", function( data ) {
console.log("success");
window.location = "login.html"; // redirect moved here, after the logout happened successfully
});
})
});
</script>
您可以onclick
从按钮中删除属性,因此您的button
html将变为
<button type="button">Logout</button>
这就是你的方式 jQuery
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句