This article shares the logout operations of jfinal and bootstrap for you, aiming to introduce how to pop up the logout confirmation box through the a tag, then send an exit request to jfinal, and then refresh the page. The main difficulties are the following two points:
1. If the login confirmation box pops up through the content of the tag a;
2. How to refresh the corresponding pop-up page through the a tag.
1. Front-end technology
1. Build a tag
Copy the code code as follows: <a href="${ctx}/mem/logout" target="ajaxTodo" callback="ajaxDone" atitle="Are you sure you want to exit?" id="user_login_out" style="padding: 0 6px;">Exit</a>
Notice:
1. target=”ajaxTodo”, specify that the a tag is to initiate a request through ajax.
2. callback=”ajaxDone”, specify the a tag callback function
3. atitle="Are you sure you want to exit?", specify the confirmation information
2. Initialize a tag ajax event
function initUI(_box) { var $p = $(_box || document); // dwz.ajax.js if ($.fn.ajaxTodo) { $("a[target=ajaxTodo]", $p).ajaxTodo(); }}Notice:
1. After the page loading is completed, execute the initUI method, so that the a tag with target is ajaxTodo has the specified ajaxTodo method.
3. Ajax request for a tag
function ajaxTodo(url, callback) { var $callback = callback; if (!$.isFunction($callback)) { $callback = eval('(' + callback + ')'); } var forwardUrl = window.location.href; if (url.indexOf("?") != -1) { url += "&forwardUrl=" + forwardUrl; } else { url += "?forwardUrl=" + forwardUrl; } $.ajax({ type : 'POST', url : url, dataType : "json", cache : false, success : $callback, error : YUNM.ajaxError });}Notice:
1. forwardUrl logs the logged out page
4. Add ajaxTodo method to jquery object
$.fn.extend({ ajaxTodo : function() { return this.each(function() { var $this = $(this); $this.click(function(event) { var url = unescape($this.attr("href")).replaceTmById($(event.target).parents(".unitBox:first")); YUNM.debug(url); if (!url.isFinishedTm()) { $.showErr($this.attr("warn")); return false; } var title = $this.attr("atitle"); if (title) { $.showConfirm(title, function() { ajaxTodo(url, $this.attr("callback")); }); } else { ajaxTodo(url, $this.attr("callback")); } event.preventDefault(); }); }); },}); },});5. Callback function
function ajaxDone(json) { YUNM.ajaxDone(json); if (json[YUNM.keys.statusCode] == YUNM.statusCode.ok || json[YUNM.keys.statusCode] == YUNM.statusCode.info) { // If the page after the transfer is specified, turn it if (json.forwardUrl) { location.href = json.forwardUrl; } }}6. Weebox confirmation box pops up
$.showConfirm = function(str, funcok, funcclose) { var okfunc = function() { $.weeboxs.close("yunm_confirm_box"); funcok.call(); }; $.weeboxs.open(str, { boxid : 'yunm_confirm_box', contentType : 'text', showButton : true, showCancel : true, showOk : true, title : 'confirm', width : 280, type : 'wee', onopen : function() { init_ui_button(); }, onclose : funcclose, onok : okfunc });};function init_ui_button() { $("button.ui-button[init!='init']").each(function(i, o) { $(o).attr("init", "init"); // To prevent repeated initialization of $(o).ui_button(); });}2. jfinal technology
public void logout() { if (getSession().getAttribute("username") != null) { // Clear session getSession().removeAttribute("username"); } ajaxDoneSuccess("Login successfully!"); renderJson();}Add logout method.
Effect:
If you still want to study in depth, you can click here to study and attach 3 exciting topics to you:
Bootstrap learning tutorial
Bootstrap practical tutorial
Bootstrap plug-in usage tutorial
The above is all about this article. I hope everyone can start to implement Bootstrap + jfinal exit system confirmation box. I hope everyone likes this article and thank you for reading.