Javascript UDF _ javascript skills

Source: Internet
Author: User
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  
   
   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.