This article mainly explained to you about the use of Ajax details, as well as examples in the proof, so that you can more quickly read the content of the article. Now let's see this article together.
Syntax: $.ajax ([Settings]);
$.ajax ({ type: "POST", URL: "Userlogincheck", data: {username:$ ("#username"). Val (), password:$ ("# Password "). Val (), verify:$ (" #verify "). Val ()}, DataType:" JSON ", success:function (data) { if (data==1) { //user name or password error alert ("User name or password error"); } else if (data==2) { alert ("Authenticode error"); Authenticode error } else if (data==0) { window.location.href= "index"; } Jump page }, error:function (XMLHttpRequest, Textstatus, Errorthrown) {//Call this function when the request fails Console.log ( Xmlhttprequest.status); Console.log (xmlhttprequest.readystate); Console.log (Textstatus); } });
PHP as the background processing process
< /span>
Public Function Userlogincheck () {//User login verification (username and mailbox can be logged in) $very = new \think\verify (); if ($very->check ($_post[' verify ')) {//Verify code is correct $user _admin = I (' Post.username '); $judge = "(user_name = ' $user _admin ' or user_email = ' $user _admin ')"; $user _del_status = $this->user->where ($judge)->getfield (' User_del '); if ($user _del_status = = 0) {//user is not logged off $user _password = I (' Post.password '); $judge. = "and User_password = ' $user _password '"; $res = $this->user->where ($judge)->find (); if ($res) {//record user login status $_session[' admin_user_id '] = $this->user->where ($judge)->getfield (' User_ID '); $_session[' admin_user_name '] = $data [' user_name ']; $this->ajaxreturn (0);//Login Successful} $this->ajaxreturn (1);//user name or password error} else $this Ajaxreturn (8);//user information is unregistered} else $this->ajaxreturn (2);//Captcha Error }
An explanation of Ajax parameters:
Data
Type: String
Data sent to the server. is automatically converted to the request string format. The GET request will be appended to the URL. View the ProcessData option description to disallow this automatic conversion. Must be a key/value format. If an array, JQuery automatically corresponds to the same name for the different values. such as {foo:["bar1", "Bar2"]} converted to ' &foo=bar1&foo=bar2 '. (want to see more on the Topic.alibabacloud.comAJAX Development Manual section of the study)
Datafilter
Type: Function
The preprocessing function for the raw data returned by Ajax. Data and type two parameters are provided: Data is the original data returned by Ajax, and type is the DataType parameter supplied when calling Jquery.ajax. The value returned by the function will be further processed by JQuery.
DataType
Type: String
Expected data type returned by the server. If not specified, JQuery is automatically judged intelligently based on the HTTP packet mime information, such as the XML MIME type being recognized as XML. In 1.4, JSON generates a JavaScript object, and script executes it. The data returned by the server is then parsed against this value and passed to the callback function. Available values:
"XML": Returns an XML document that can be processed with jQuery.
HTML: Returns plain text HTML information, and the included script tag is executed when the DOM is inserted.
"Script": Returns plain text JavaScript code. Results are not automatically cached. Unless the "cache" parameter is set. Note: On remote requests (not in the same domain), all POST requests are converted to GET requests. (because the script tag of the DOM will be used to load)
"JSON": Returns the JSON data.
"JSONP": Jsonp format. When calling a function using JSONP form, such as "myurl?callback=?" JQuery is automatically replaced? is the correct function name to execute the callback function.
"Text": Returns a plain text string
Error
Type: Function
Default value: Auto-Judgment (XML or HTML). This function is called when a request fails.
There are three parameters: the XMLHttpRequest object, the error message, and (optionally) the exception object that is caught.
If an error occurs, the error message (the second argument) may also be "timeout", "error", "Notmodified", and "ParserError", in addition to being null.
This is an Ajax event.
Global
Type: Boolean
Whether to trigger global AJAX events. Default value: True. Setting to FALSE will not trigger global AJAX events, such as Ajaxstart or ajaxstop, which can be used to control different AJAX events.
Ifmodified
Type: Boolean
Get new data only when the server data changes. Default value: False. Use the HTTP packet last-modified header information to determine. In JQuery 1.4, it also checks the server-specified ' ETag ' to determine that the data has not been modified.
Jsonp
Type: String
Overrides the name of the callback function in a JSONP request. This value is used instead of the "callback" part of the URL parameter in the "callback=?" Get or POST request, such as {jsonp: ' onjsonpload '} will cause the "onjsonpload=?" to be passed to the server.
Jsonpcallback
Type: String
Specifies a callback function name for the JSONP request. This value will be used instead of the random function name generated by jQuery automatically. This is primarily used to create a unique function name for JQuery, which makes it easier to manage requests and provides a convenient way to provide callback functions and error handling. You can also specify this callback function name when you want the browser to cache a GET request.
Password
Type: String
Password in response to HTTP access authentication request
ProcessData
Type: Boolean
Default value: True. By default, the data option is passed in, and if it is an object (technically, as long as it is not a string), it will be processed into a query string to match the default content type "application/x-www-form-urlencoded". Set to False if you want to send DOM tree information or other information that you do not want to convert.
Scriptcharset
Type: String
Only if the request is dataType as "Jsonp" or "script", and type is "GET" is used to force the modification of CharSet. Typically used only when local and remote content encodings are different.
Success
Type: Function
The callback function after the request succeeds.
Parameters: The data returned by the server and processed according to the DataType parameter; A string describing the state.
This is an Ajax event.
Traditional
Type: Boolean
If you want to serialize the data in a traditional way, set it to true. Please refer to the Jquery.param method under the Tools category.
Timeout
Type: Number
Sets the request time-out (in milliseconds). This setting overrides the global settings.
Type
Type: String
Default value: "GET"). The request method ("POST" or "get"), the default is "get". Note: Other HTTP request methods, such as PUT and DELETE, can also be used, but only some browsers support it.
Url
Type: String
Default value: The current page address. The address where the request was sent.
Username
Type: String
The user name used to respond to HTTP access authentication requests.
Xhr
Type: Function
You need to return a XMLHttpRequest object. The default is ActiveXObject under IE and in other cases is xmlhttprequest. Used to override or provide an enhanced XMLHttpRequest object. This parameter is not available until JQuery 1.3.
This is the end of this article (want to see more on the Topic.alibabacloud.comAJAX User manual section of the study), there are questions can be in the message below the question.