Serialize () Method:
Acts on a jquery object, which serializes the contents of the DOM elements into strings for Ajax requests.
<!DOCTYPE HTML><HTML><HeadLang= "en"> <MetaCharSet= "UTF-8"> <Scripttype= "Text/javascript"src=".. /.. /js/jquery-2.1.3.js "></Script> <style> * {margin:0;padding:0;}Body{font-size:12px;}. Comment{Margin-top:10px;padding:10px;Border:1px solid #ccc;background:#DDD;}. Comment h6{Font-weight: the;font-size:14px;}. Para{Margin-top:5px;text-indent:2em;background:#DDD;} </style> <title></title></Head><Body><formID= "Form1"Action="#"> <P>Comments:</P> <P>Name:<inputtype= "text"name= "username"ID= "username" /></P> <P>Content:<textareaname= "Content"ID= "Content"rows= "2"cols= " the"></textarea> </P> <P><inputtype= "button"ID= "Send"value= "Submit"></P></form><Divclass= "comment">Comments already available:</Div><DivID= "ResText"></Div></Body><Scripttype= "Text/javascript"> $(function () { $("#send"). Click (function () { //This approach can be used in a form with only a small number of fields, but if the form elements are becoming more complex, use this method to increase the workload while //also makes the form inflexible. jquery provides a simplified method for this common operation----serialize ()//$.get ("get1.jsp", {//Username:encodeuri ($ ("#username"). Val ()),//Content:encodeuri ($ ("#content"). Val ())//}, function (data, textstatus) {//$ ("#resText"). HTML (decodeURI (data));// }); //The serialize () method works with a jquery object, which serializes the contents of a DOM element into a string and is used for AJAX requests. $.get ("get1.jsp", $("#form1"). Serialize (),function(data, Textstatus) {$ ("#resText"). HTML (data); }) }); /** * Because the Serialize () method is used for jquery objects, not only the form can use it, but also the elements selected by other selectors can use it, such as the following jquery code: * $ (": Checkbox,:radio") . Serialize (); * Serializes the values of checkboxes and radio boxes into strings, only serializes the selected values * * * * Serializearray () method * This method does not return a string, but instead serializes the DOM element. Returns data in JSON format. * * * * $.param () method. It is the core of the Serialize () method, which is used to serialize an array or an object according to Key/value. * * For example: * var obj = {a:1, b:2, c:3}; * var k = $.param (obj); * Alert (k);//Output a=1&b=2&c=3 * **/ })</Script></HTML>
Ajax Global Events:
| Method name |
Description |
| Ajaxcomplete (callback) |
Functions that are executed when an AJAX request completes |
| Ajaxerror (callback) |
The function that the AJAX request executes when an error occurs, and the catch error can be passed as the last argument |
| Ajaxsend (callback) |
Functions executed before Ajax request is sent |
| Ajaxsuccess (callback) |
Functions executed when the AJAX request succeeds |
Sharp jquery Reading Notes---ajax--serialization elements, AJAX global events in jquery