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