[英]how to use php code after bootbox confirm alert
我想在用户确认后执行一些php代码。 我的意思是,如果用户单击“是”,则应执行一些php函数。 我该怎么做?
bootbox.confirm({ message: "This is a confirm with custom button text and color! Do you like it?", buttons: { confirm: { label: 'Yes', className: 'btn-success' }, cancel: { label: 'No', className: 'btn-danger' } }, callback: function (result) { console.log('This was logged in the callback: ' + result); } });
PHP代码在服务器端执行(在客户端看到页面之前),并且php代码被删除为输出给用户的内容。
要执行一些PHP代码,您需要向服务器发出另一个请求。 为此,您可以使用XMLHTTPRequests或Ajax。
如Ad5001 Gameur codeur autre所述 ,您已提出请求。 这是一个例子:
<script type="text/javascript">
function loadXMLDoc() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE ) {
if (xmlhttp.status == 200) {
document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
}
else if (xmlhttp.status == 400) {
alert('There was an error 400');
}
else {
alert('something else other than 200 was returned');
}
}
};
xmlhttp.open("GET", "ajax_info.txt", true);
xmlhttp.send();
}
</script>
用户单击“是”后,您将调用函数(在本例中为loadXMLDoc()
)。
不要忘记用您的PhP文件替换ajax_info.txt
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.