This article mainly introduces javascript custom callback functions. For more information, see
Background Analysis
First, let's take a look at a piece of js code. when adding a JavaScript code, we first use an asynchronous request to determine whether it exists. if it does not exist, we will perform the ADD operation:
function add(url,data) { var isExited = isExited(data); if(!isExited){ addRequest(url, data); }}
When I add a piece of data, I first determine whether the data exists in the database (of course, if the front and back ends are completely separated, the front end should not judge the business logic. the front end should only, first, isExited () requests are implemented by ajax requests. this is asynchronous. Obviously, when the interface does not return results, execute the following function (usually yes) so that the isExited value is undefined. this is obviously not what you want. to implement similar functions, you can use the callback function, the following is a case study.
The procedure is as follows:
The front-end jsp interface is as follows:
<% @ Page language = "java" contentType = "text/html; charset = UTF-8 "pageEncoding =" UTF-8 "%> <% @ taglib prefix =" c "uri =" http://java.sun.com/jsp/jstl/core "%>
JS callback function case