When I check whether the user name exists, there will be a delay in writing ajax. how can I detect it in real time based on the input content.

Source: Internet
Author: User
When I check whether the user name exists, there will be a delay in writing ajax. how can I detect it in real time based on the input content.
// Check whether the user name exists $ ('input [name = "name"] '). focus (function () {$ (". state1 ").html (" username must be 3-20 characters ");}). keypress (function () {if ($ (this ). val (). length> = 3 & $ (this )). val (). length <= 12 & $ (this )). val ()! = '') {$. Get ("deal. php ", {username: $ (" # name "). val ()}, function (data) {if (data. status = 1) {$ (". state1 "example .html ('user name already exists '); ok1 = false;} else {$ (". state1 ").html (" correct user name "); ok1 = true ;}}, 'json');} else {$ (". state1 ").html (" username should be 3-20 characters "); ok1 = false ;}});


Reply to discussion (solution)

Ajax requires access to the server, and there is a latency.
If you want to use this dynamic effect, you must naturally tolerate its shortcomings.

Ajax requires access to the server, and there is a latency.
If you want to use this dynamic effect, you must naturally tolerate its shortcomings.

Can I use settimeout to set the delay time?

No
It always takes time to access the server.

In fact, if you really feel a high latency (more than 2 seconds), you should consider whether your network is poor or the server program is too bad.

Ajax is used. the latency is too long, or your server is too bad.

This is not a matter of seconds, unless you are willing to move all the company names in the library to the front end

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.