Sharp jQuery 2nd learning notes Chapter 6 and Chapter 7, jquery learning notes Chapter 7

Source: Internet
Author: User
Tags getscript jquery form validation

Sharp jQuery 2nd learning notes Chapter 6 and Chapter 7, jquery learning notes Chapter 7
Chapter 2, ajax Advantages and Disadvantages of jQuery and Ajax applications 1. No plug-in support 2. Excellent user experience 3. Improved Web program performance 4. reduced load on servers and bandwidth lack of Ajax 1. Lack of support for XMLHttpRequest objects by the browser 2. Destruction of normal functions of the browser forward and backward buttons 3. Lack of support for search engines 4. Lack of development and debugging tools the core of Ajax XMLHttpRequest is the XMLHttpRequest object, it is the key to Ajax implementation-it is used to send asynchronous requests, receive responses, and execute callbacks. IE5 and IE6 introduce the XMLHttpRequest object in ActiveXObject mode, while the XMLHttpRequest object of other browsers is the Ajax1 and load () method syntax structure of window sub-objects in jQuery: load (url [, data] [, callback])Parameters of the load () method

Parameters Type Description
Url String Request the url of the HTML page
Data (optional) Object Key/value data sent to the server
Callback (optional) Function The callback function when the request is complete, whether the request is successful or fails.
Filter loaded HTML documents
$ ('# ResText'). load ("test.html. para"); // loads the content of the class as "para" on the test.html page.
Transfer ModeThe load () method is automatically specified based on the parameter data. If any parameter is passed as the POST method, if no parameter is set, the GET method is used. Callback FunctionThere are three parameters: 1. Content returned by the request; 2. Request status; 3. XMLHttpRequest object Note: It is usually used to obtain static files from the Web server 2, $. get () and $. post () method (1) $. get () uses the GET Method for asynchronous request syntax structure: $. get (url [, data] [, callback] [, type]); $. Get () method parameter explanation
Parameters Type Description
Url String Url of the requested HTML page
Data (optional) Object The key/value data sent to the server is appended to the request URL.
Callback (optional) Function The callback function automatically passes the request results and status to the method when the load is successful.
Type (optional) String The format of the content returned by the server, such as xml, html, script, json, text, and _ default.
Callback FunctionThere are only two parameters: 1. data, returned content, xml file, json file, etc.; 2. Request status: success, error, notmodified, timeout Note: only when the data is successfully returned (success) is called (2) $. post () uses the POST method for asynchronous requests Difference between GET and POST<1> a GET request transmits parameters after a URL, while a POST request sends a Web server as an HTTP object. <2> GET has a limit on the size of data to be transmitted (usually not greater than 2 kb), while POST is more than GET (theoretically unlimited) <3> GET requests are cached by browsers, which may cause serious security problems in some cases, while POST can avoid <4> the methods for obtaining data transmitted by GET and POST on the server are also different. 3, $. getScript () method and $. getJson () method (1) $. getScript () use $. loading a js file using the getScript () method is as simple as loading an HTML page, and does not need to process the js file. The js file will be automatically executed. Callback FunctionIt will be executed after js loading is successful (2) $. getJson () $. getJson () is used to load a json File $. the each () method is used in jQuery to traverse objects and arrays. Two parameters are accepted: 1. array or object. 2. Callback Function (two parameters are accepted: 1. Object member or array index; 2. corresponding variables or content) 4. $. ajax () method syntax structure: $. in the ajax (options) options object, parameters exist in the form of key/value. All parameters are optional $. the ajax () method has a large number of parameters and requires additional information to be queried before adding serialization elements. 1. serialize () methodActing on a jQuery object, you can serialize the content of DOM elements into strings for Ajax requests. Note: When passing parameters, you must encode the parameters, that is, using URI encoding, if you do not want the encoding to be troublesome, you can use the serialize () method, which will automatically encode 2. serializeArray () methodAfter the DOM is serialized, data in json format is returned. 3. $. param () methodThe core of the serialize () method is used to serialize an object by key/value. The Ajax global event in jQuery triggers the callback function of the ajaxStart () method when the Ajax request starts; when an Ajax request ends, the callback function of the ajaxStop () method is triggered. Other global methods
Method Name Description
AjaxComplete (callback) Execute the function when the Ajax request is complete.
AjaxError (callback) Execute the function when an error occurs in an Ajax request. The caught error can be passed as the last parameter.
AjaxSend (callback) Functions executed before an Ajax request is sent
AjaxSuccess (callback) Execute the function when the Ajax request is successful.
Chapter 2 jQuery Form Validation plug-in-use and writing of jQuery plug-ins-Validation :Http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API:Http://docs.jquery.com/plugins/validatioinjquerytable single plug-in --formcore: ajaxform () and ajaxSubmit () :Both http://jquery.malsup.com/form/#downloadajaxForm () and ajaxSubmit () can accept 0 or 1 parameter, when it is a single parameter, either a callback function or an options object, by passing the options object, give them more control over the form. Modal window plug-in-SimpleModal :Bytes:
$("#elementid").modal();
2. As a separate function:
$.modal("<div>Either method can receive an optional parameter: options
$("#elementid").modal({options});$.modal("<div>
API:Http://www.ericmmartin.com/projects/simplemodal/manage cookieplug-In --cookie
:Http://github.com/carhartl/jquery-cookiejQuery UI plug-in
:Http://ui.jquery.com/downloadhttp://jqueryui.com/downloadwrite jqueryplug-in
1. Plug-ins

(1) plug-ins that encapsulate object methods (2) plug-ins that encapsulate global functions (3) selector plug-ins 2. Plug-ins(1) jQuery plug-in is recommended. [plug-in name]. js (2) All object methods should be appended to jQuery. on the fn object, all global functions should be appended to the jQuery object itself (3) inside the plug-in, this points to the jQuery object currently obtained through the selector (4) you can use this. each to traverse all elements (5) All methods or function plug-ins should end with a semicolon (6) the plug-in should return a jQuery object to ensure that the plug-in can be chained (7) avoid using $ as the alias of the jQuery object in the plug-in. Use the complete jQuery representation to avoid conflicts. Of course, you can also use closures to avoid this problem. jQuery plug-in mechanism jQuery provides two methods for extending jQuery functions, that is, jQuery. fn. extend () and jQuery. extend () jQuery. fn. extend () is used to extend the first type of plug-in, jQuery. extend () is used to extend the last two plug-ins

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.