Pick UP:
6. Ajax:
A basic underlying function: Jquery.ajax (); This function is called by the Advanced tool function;
An advanced tool method: Load ();
Four advanced tool functions: Jquery.getscript (), Jquery.getjson (), $.get (), $.post ();
- Load (): is a method that passes a URL to it that asynchronously loads the contents of the URL and then inserts the content into the selected element to replace the existing content, such as: $ ("#status"). Load (' status.html '); If you want to display only a portion of the document that is loaded, you can add a space after the URL and a jquery selector. Form: $ ("#status"). Load ("status.html #tmp"); the
- load () method can have two optional parameters, the first optional parameter represents the data, and if it is a string, it can be appended to the URL Sending a GET request, as a data object, is converted to a POST request after a & delimited pair of k-v pairs, and the other optional parameter is a callback function with three parameters: the text of the loaded URL, the status code string (success, notmodified, error , timeout, parsererror), XMLHttpRequest object that loads the URL,
- $.getscript (): Loads the JS code file, the first parameter is the URL of the JS file (cross-domain), and the second parameter that is optional is the callback function , shaped like: Jquery.getscript (' Http://..../.js ', function () {...}); The callback function will be called after the completion of the execution of the file, there are three parameters, in the case of homologous script, the parameters are the same as the load () method callback function, when cross-domain request, the first and third parameters are undefined, function return value is undefined;
- $.getjson (): Similar to load (), gets the text first, after special processing (should be called $.parsejson ()) to the specified callback function as the first parameter. So you have to pass in the callback function as a parameter, otherwise it doesn't make sense; the
- jquery.get () and Jquery.post () methods are usually implemented by this function:
- $.ajax (): All Ajax tools for jquery call this function, which receives only one parameter: an option object;
You can set the default value for all AJAX requests, usually without this function, but directly at the AJAX request, with the same effect:
$.ajaxsetup ({contentType:' Application/json ',//Specifies the HTTP Content-type header for the request;DataType: ' JSON ',//Specify the expected type of response data and how jquery handles the data [text,html,script,json,xml ...]timeout:2000,//Timeout, unit MS, default 0, if set this, the time is not completed request, the request is canceled and trigger error callback, status code timeout;Cachefalse,//disables browser caching, and when set to False for GET requests, the URL adds "_= milliseconds for the current time";Asyn:true,//If the request is asynchronous, the default is true, set false. Can block the current process until the response, equivalent to the synchronization request;});//set AJAX request address and callback function$.ajax ({type:' GET ',//HTTP request method, default get other has post DELETE put, etc.;URL: ' url ... ',//the requested URLdata:{},//The sending request is the passed data, which can be a string or an object, placed in the URL or in the request content body;Beforesend:function(XHR) {},//Specifies the callback function before the AJAX request is sent; two parameters XMLHttpRequest object with the requested option object;//mainly used to set the XHR object on the custom HTTP header, return FALSE, the request will be canceled;Successfunction(RESPONSE,STATUSCODE,XHR) {},//callback function when the request succeeds; three parameters: Data returned by the server, jquery status code//and send the change Request XMLHttpRequest object, generally only need the first parameter;Errorfunction(Xhr,statuscode,error) {},//callback function when the request is unsuccessful; three arguments: The XMLHttpRequest object that sent the request//jquery Status Code, the Error object thrown;Completefunction(Xhr,statuscode) {}//A callback function that is activated when the request is completed (after calling sucess or error); only two parameters, generally not used;});
7. Useful tool functions in jquery:
8. jquery Selector and selection method
JavaScript class Library---JQuery (ii)