JQuery's extend extension method:
Jquery's extension method extend is a commonly used method when we write plug-ins. This method has Some overloaded prototypes, let’s learn about them together.
1. Jquery’s extension method prototype is:
##extend(dest,src1,src2,src3...);
Its meaning is to merge src1, src2, src3... into dest, and the return value is the merged dest. It can be seen that this method modifies the structure of dest after merging. If you want to get the merged result but don’t want to modify the structure of dest, you can use it as follows:varnewSrc=$.extend({},src1 ,src2,src3...)//That is, use "{}" as the dest parameter.
In this way, src1, src2, src3... can be merged, and then the merged result will be returned to newSrc. For example:varresult=$.extend({},{name:"Tom ",age:21},{name:"Jerry",sex:"Boy"})
Then the merged resultresult={name:"Jerry ",age:21,sex:"Boy" }
That is to say, if the later parameter has the same name as the previous parameter, then the later parameter will overwrite the previous parameter value. $.extend(settings, options);//Merge settings and options, and return the merged result to settings, which is equivalent to options inheriting setting and saving the inherited result in setting.
var settings = $.extend({}, defaults, options);
//Merge defaults and options, and return the merged result to the setting without overwriting the default content.
2. Omit the dest parameter The dest parameter in the prototype of the extend method mentioned above can be omitted. If it is omitted, the method can only have one src. Parameters, and merge the src into the object that calls the extend method, such as:
1, $.extend(src)
This method is to merge the src into the global object of jquery in, such as:
$.extend({hello:function(){alert(
'hello ');}});
2.$.fn.extend(src)
This method merges src into the jquery instance object, such as:
$.fn.extend({hello:function(){alert(
'hello');} });
$.extend({net:{}});
namespace in the jquery global object.
$.extend($.net,{hello:function(){alert(
'hello' );}})
3. Jquery’s extend method also has an overloaded prototype:
##extend(boolean,dest,src1,src2,src3...)The first parameter boolean represents whether to perform a deep copy. The other parameters are consistent with the previous introduction. What is a deep copy? Let’s look at an example:
varresult=$.extend(true, {},
{ name: "John", location: {city:"Boston ",county:"USA"}
},
{ last: "Resig", location: {state:"MA",county:"China"}
} );
We can see that the sub-object location: {city: "Boston"} is nested in src1, and the sub-object location: {state: "MA"} is also nested in src2. If a deep copy parameter is true, then the merged result is:
result={name:"John",last:"Resig",
location:{city:"Boston",state:" MA",county:"China"}}
That is to say, it will also merge the nested sub-objects in src. If the first parameter boolean is false, let's see what the result of the merger is, as follows:
varresult=$.extend(false, {},
{ name: "John", location:{city:"Boston" ,county:"USA"}
},
{ last: "Resig", location: {state:"MA",county:"China"}
}
);
Then the result after merging is:
result={name:"John" ,last:"Resig",location:{state:"MA ",county:"China"}}
$.extend({
min: function(a, b){return a < b?a:b; },
max: function(a, b){return a > b ?a:b; }
}); //Extended min and max methods for jquery
Use the extended method (called through "$.method name"):
alert("a= 10,b=20,max="+$.max(10,20)+",min="+$.min(10,20));
The above are some details that $.extend() is often used in projects.
posted @ 2010-11-24 21:13 xiaoxiaohui Read(48) Comment(0) Edit
HTTP request header information
Overview of HTTP request headers (HttpServletRequest) HTTP client programs (such as browsers) must specify the request type (usually GET or POST or HEAD) when sending a request to the server.
If necessary, the client program can also choose to send other request headers. Most request headers are not required, except Content-Length. Content-Length must be present for POST requests. The following is an overview of some of the most common HTTP request headers (HttpServletRequest)
HTTP client programs (such as browsers) must specify the request type (usually GET or POST) when sending a request to the server. The client program can also choose to send additional request headers if necessary. Most request headers are not required, except Content-Length. Content-Length must be present for POST requests.
The following are some of the most common request headers
Accept: MIME types accepted by the browser.
Accept-Charset: The character set acceptable to the browser.
Accept-Encoding: The data encoding method that the browser can decode, such as gzip. Servlets can return gzip-encoded HTML pages to browsers that support gzip. In many cases this can reduce download times by 5 to 10 times.
Accept-Language: The language type desired by the browser, used when the server can provide more than one language version.
Authorization: Authorization information, usually appears in the response to the WWW-Authenticate header sent by the server.
Connection: Indicates whether a persistent connection is required. If the servlet sees the value here as "Keep-Alive", or sees that the request is using HTTP 1.1 (HTTP 1.1 makes persistent connections by default), it can take advantage of persistent connections when the page contains multiple elements (e.g. Applet, picture), significantly reducing the time required for downloading. To achieve this, the Servlet needs to send a Content-Length header in the response. The simplest way to achieve this is to first write the content to a ByteArrayOutputStream, and then calculate its size before officially writing the content out.
Content-Length: Indicates the length of the request message body.
Cookie: This is one of the most important request header information
From: The email address of the request sender, which is used by some special web client programs and will not be used by the browser.
Host: The host and port in the initial URL.
If-Modified-Since: Return the requested content only if it has been modified after the specified date, otherwise return a 304 "Not Modified" response.
Pragma: Specifying a "no-cache" value indicates that the server must return a refreshed document, even if it is a proxy server and already has a local copy of the page.
Referer: Contains a URL from which the user accesses the currently requested page.
User-Agent: Browser type, this value is very useful if the content returned by the Servlet is related to the browser type.
UA-Pixels, UA-Color, UA-OS, UA-CPU: non-standard request headers sent by some versions of IE browser, indicating screen size, color depth, operation System and CPU type.
HTTP response header overview (HttpServletResponse)
The HTTP response of a web server generally consists of the following items: a status line, one or more response headers, a blank line, and a content document. Setting HTTP response headers is often combined with setting the status code in the status line. For example, several status codes indicating "The document location has changed" are accompanied by a Location header, while the 401 (Unauthorized) status code must be accompanied by a WWW-Authenticate header.
However, it is useful to specify response headers even when no status code with special meaning is set. Response headers can be used to: set cookies, specify modification dates, instruct the browser to refresh the page at specified intervals, declare the length of the document in order to utilize persistent HTTP connections, ... and many other tasks.
The most commonly used method to set the response header is setHeader of HttpServletResponse. This method has two parameters, which represent the name and value of the response header respectively. Similar to setting status codes, setting response headers should be done before sending any document content.
The setDateHeader method and the setIntHeadr method are specifically used to set response headers containing dates and integer values. The former avoids the trouble of converting Java time to GMT time strings, and the latter avoids the trouble of converting integers to strings.
HttpServletResponse also provides many settings
setContentType: Set the Content-Type header. Most Servlets use this method.
SetContentLength: Set the Content-Length header. This function is useful for browsers that support persistent HTTP connections.
addCookie: Set a Cookie (there is no setCookie method in the Servlet API, because the response often contains multiple Set-Cookie headers).
In addition, as introduced in the previous section, the sendRedirect method will also set the Location header when setting status code 302.
HTTP response header description
Allow Which request methods are supported by the server (such as GET, POST, etc.).
Content-Encoding The encoding (Encode) method of the document. Only after decoding can the content type specified by the Content-Type header be obtained. Using gzip to compress documents can significantly reduce the download time of HTML documents. Java's GZIPOutputStream can easily perform gzip compression, but only Netscape on Unix and IE 4 and IE 5 on Windows support it. Therefore, the Servlet should check whether the browser supports gzip by looking at the Accept-Encoding header (i.e. request.getHeader("Accept-Encoding")), return a gzip-compressed HTML page for browsers that support gzip, and return a normal HTML page for other browsers. page.
Content-Length represents the content length. This data is only required if the browser uses persistent HTTP connections. If you want to take advantage of persistent connections, you can write the output document to ByteArrayOutputStream, check its size when completed, then put the value into the Content-Length header, and finally send the content via byteArrayStream.writeTo(response.getOutputStream().
Content-Type indicates what MIME type the following document belongs to. Servlet defaults to text/plain, but it usually needs to be explicitly specified as text/html. Since Content-Type is often set, HttpServletResponse provides a dedicated method setContentTyep. .
Date The current GMT time. You can use setDateHeader to set this header to avoid the trouble of converting the time format.
Expires When should the document be considered expired and no longer be cached? Modified The last modification time of the document. The client can provide a date through the If-Modified-Since request header. The request will be treated as a conditional GET. Only documents with modification time later than the specified time will be returned, otherwise a 304 (Not) will be returned. Modified) status. Last-Modified can also be set by the setDateHeader method.
Location indicates where the client should go to retrieve the document. Location is usually not set directly, but through the sendRedirect method of HttpServletResponse, which also sets the status code to 302. .
Refresh indicates the time after which the browser should refresh the document, in seconds. In addition to refreshing the current document, you can also pass setHeader("Refresh", "5; URL=http://host/path" ) Let the browser read the specified page. Note that this function is usually set by setting the in the HEAD area of the HTML page. Implementation, this is because automatic refresh or redirection is very important for HTML writers who cannot use CGI or Servlet. However, for Servlet, it is more convenient to set the Refresh header directly. Note that Refresh means "refresh this page after N seconds." page or access the specified page" rather than "refresh this page or access the specified page every N seconds". Therefore, continuous refresh requires sending a Refresh header each time, and sending a 204 status code can prevent the browser from continuing to refresh regardless of Whether to use Refresh header or . Note that the Refresh header is not part of the official HTTP 1.1 specification, but is an extension, but both Netscape and IE support it.
Server server name. Servlets generally do not set this value, but are set by the web server itself.
Set-Cookie sets the cookie associated with the page. Servlets should not use response.setHeader("Set-Cookie", ...), but should use the dedicated method addCookie provided by HttpServletResponse. See discussion of cookie settings below.
WWW-Authenticate What type of authorization information should the client provide in the Authorization header? This header is required in responses containing a 401 (Unauthorized) status line. For example, response.setHeader("WWW-Authenticate", "BASIC realm=\"executives\""). Note that Servlets generally do not handle this aspect, but let the Web server's specialized mechanism control access to password-protected pages (such as .htaccess).
Error code explanation
"100" : Continue
"101" : witching Protocols
"200" : OK
"201" : Created
"202" : Accepted
"203" : Non-Authoritative Information
"204" : No Content
"205" : Reset Content
"206" : Partial Content
"300" : Multiple Choices
"301" : Moved Permanently
"302" : Found
"303" : See Other
"304" : Not Modified
"305" : Use Proxy
"307" : Temporary Redirect
HTTP 400 - Invalid request
HTTP 401.1 - Unauthorized: Login failed
HTTP 401.2 - Unauthorized: Server configuration problem caused login failure
HTTP 401.3 - ACL prohibits access to the resource
HTTP 401.4 - Unauthorized: Authorization denied by filter
HTTP 401.5 - Unauthorized: ISAPI or CGI authorization failed
HTTP 403 - Access Forbidden
HTTP 403 - Access to Internet Services Manager (HTML) is restricted to Localhost
HTTP 403.1 Forbidden: Executable access is prohibited
HTTP 403.2 - Forbidden: Read access is prohibited
HTTP 403.3 - Forbidden: Write access is prohibited
HTTP 403.4 - Forbidden: SSL required
HTTP 403.5 - Forbidden Access: SSL required 128
HTTP 403.6 - Forbidden: IP address denied
HTTP 403.7 - Forbidden: Client certificate required
HTTP 403.8 - Forbidden: Site access forbidden
HTTP 403.9 - Forbidden : Too many connected users
HTTP 403.10 - Forbidden: Invalid configuration
HTTP 403.11 - Forbidden: Password change
HTTP 403.12 - Forbidden: Access denied by mapper
HTTP 403.13 - Forbidden: Client certificate has been revoked
HTTP 403.15 - Access Forbidden: The client has too many access permissions
HTTP 403.16 - Access Forbidden: The client certificate is untrusted or invalid
HTTP 403.17 - Access Forbidden: The client certificate has expired or has not yet been issued Effective
HTTP 404.1 - Web site not found
HTTP 404 - File not found
HTTP 405 - Resource forbidden
HTTP 406 - Unable to accept
HTTP 407 - Proxy authentication required
HTTP 410 - Never available
HTTP 412 - Prerequisite failed
HTTP 414 - Request - URI too long
HTTP 500 - Internal Server Error
HTTP 500.100 - Internal Server Error - ASP Error
HTTP 500-11 Server down
HTTP 500-12 Application restarted
HTTP 500-13 - Server too busy
HTTP 500-14 - Application invalid
HTTP 500-15 - Request not allowed global.asa
Error 501 - Not implemented
HTTP 502 - Gateway Error
The above is the detailed content of Detailed introduction and use of extend usage in JQuery. For more information, please follow other related articles on the PHP Chinese website!