JQuery_review: Required for jQuery Ajax, serialize, param method and global function, jqueryserialize

Source: Internet
Author: User

JQuery_review: Required for jQuery Ajax, serialize, param method and global function, jqueryserialize
In the project, we may encounter the following problems: the first problem is that we need to implement an ajax-based Asynchronous program. We are also quite familiar with ajax that can use {name: name, address: address. However, when the task was issued, we found that the form at the front end was very huge, and I had no patience to spell strings one by one. The second problem is that we need to pass a user survey table full of checkbox to the background. amount, do we need to write a filter and traverse it through each, then, is it possible to construct such a parameter table? If you know jQuery selector well, it can be done happily. However, a mature hacker migrant workers will certainly be able to come and see if there is any more suitable method to use it directly. Third, we agreed to use the JSON format for interaction with the background, which means we should convert the foreground content to JSON and then throw it to the background. What should we do? There must be a large number of coders who have been suffering from this kind of pain and have left a lot of treasures. This is certainly the way!
Fourth, if we design a framework to prevent users from performing page operations when sending asynchronous requests to the current page, we will add a masked effect for the current operation, what should I do if I fail to operate the current page within a period of time and can operate the current page after the asynchronous request is sent?
Fifth, the web server and the backend server often stop working in the background or cannot communicate with the backend because the network is not connected, but ajax still works normally, if there is no global mechanism to tell users, this is also very unfriendly. How should we solve this problem?
Okay, now let's answer the above question in sequence: first, please use the google "form. serialize ()" method to serialize all the content in the current form. Second, google "$ (": checkbox,: password "). serialize ()". This serialize method can be a form selector. Third, please use the google "serializeArray ()" method to convert the jQuery object into a jSon object and then interact with the background. For the fourth and fifth problems, please pay more attention to jQuery's global method. This is a series of useful methods for handling exceptions at the front end or improving user experience. There are only four to five methods, it is easier to remember. Good luck ~ @ Happy new week!

Front-end code:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">



Jquery can be used to serialize form values using serialize (). Is there any way to fill the values in the form?

Serialize () is used to generate a string similar to this format for ajax to submit a = 1 & B = 2 & c = 3. To enter a value in a form, you must first have a value, which is the id of the Form Control or the property that can uniquely locate the control. Then $ ("# id"). val ("value ")

How to Use jquery serialize to get only the value of the value part

Use serializeArray () to return JSON data and operate JSON data directly. The structure is as follows:
[{Name: 'firstname', value: 'hello'}, {name: 'lastname', value: 'World'}, {name: 'Alias '}, // The value is null.]

X = $ ("form"). serializeArray ();
Alert (x [0]. value); // The value of 'firstname' is 'Hello'
Alert (x [1]. value); // 'lastname' value 'World'

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.