Repeat the user name through SSH + Ajax (2)

Source: Internet
Author: User

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)

Related Article

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.