1. Another common JS expression:
VaR user = {inintevent: function () {$ ("input [name = 'user. user_logname'] "). unbind ("Blur");/* the user will respond when the input box is moved. user_logname is the name of the input box */$ ("input [name = 'user. user_logname'] "). BIND ("Blur", function () {user. checkuser ($ (this ). val () ;}}, checkuser: function (LOGNAME) {VaR parameter = {LOGNAME: LOGNAME/* input parameter. Why is this representation used? */};
$. Ajax ({
URL: "userjson_checkname.action", // enter the submitted action here.
Type: "Post ",
Data: {"LOGNAME": LOGNAME, "PID": 5}, // here is the parameter you submitted, you can write a lot
Datatype: "text", // data format
Cache: false,
Async: false,
Success: function (data) {// here is the data you returned
If (Data = "\" OK \ "") {/* Note the double quotation marks here */
$ ("# Message"). Text ("this user name is available ");
$ ("# Message" ).css ("color", "blue ");
} Else {
$ ("# Message"). Text ("this user name is unavailable ");
$ ("# Message" ).css ("color", "Red ");
}
},
Error: function (){
Alert ("failed to get user information. Please contact the administrator! ");
}
})
};/* Bind the action when starting the page */$ (document ). ready (function () {user. inintevent ();/* bind to user name input box */});
Note that the format of the returned data is as follows. The returned values observed when setting a javascript breakpoint in chrome are significantly different.
2. In particular, You need to note that the datatype in parameters has the following formats:
• "XML": returns an XML document, which can be processed by jquery.
• "Html": returns plain text HTML information. The 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: During remote requests (not in the same domain), all post requests are converted to GET requests. (Because the script tag of Dom will be used for loading)
• "JSON": Return JSON data.
• "Jsonp": jsonp format. When calling a function in the form of jsonp, such as "myurl? Callback =? "Will jquery be replaced automatically? For the correct function name to execute the callback function.
• "Text": returns a plain text string.
Detailed instruction Reference document: http://www.w3school.com.cn/jquery/ajax_ajax.asp
Repeat the user name through SSH + Ajax (2)