{"id":195,"date":"2008-08-28T22:14:00","date_gmt":"2008-08-28T22:14:00","guid":{"rendered":"http:\/\/blog.trungson.com\/?p=195"},"modified":"2008-08-28T22:14:00","modified_gmt":"2008-08-28T22:14:00","slug":"check-username-availability-via-ajax-with-jquery","status":"publish","type":"post","link":"http:\/\/blog.trungson.com\/?p=195","title":{"rendered":"Check username availability via AJAX with jQuery"},"content":{"rendered":"<p>HTML<br \/>\n<textarea name=\"code\" class=\"html\"><br \/>\n<input name=\"UserName\" id=\"UserNameInputID\" type=\"text\" \/><br \/>\n<span id=\"loading\"><img decoding=\"async\" src=\"loading.gif\" alt=\"i\" \/> Checking&#8230;<\/span><br \/>\n<\/textarea><br \/>\nJavaScript<br \/>\n<textarea name=\"code\" class=\"js\"><br \/>\n$(&#8220;#loading&#8221;).hide();<br \/>\nvar orig=$(&#8220;#loading&#8221;).html();<br \/>\n$(&#8220;#UserNameInputID&#8221;).blur(function() {<br \/>\n  $(&#8220;#loading&#8221;).html(orig);<br \/>\n  $(&#8220;#loading&#8221;).show();<br \/>\n  loadTextPage(&#8220;loading&#8221;,&#8221;check.php?username=&#8221;+$(&#8220;#UserNameInputID&#8221;).val());<br \/>\n});<\/p>\n<p>\/** load a text page into this div *\/<br \/>\nfunction loadTextPage($pDivID,$pURL) {<br \/>\n  $.ajax({<br \/>\n    url:$pURL,<br \/>\n    dataType:&#8217;html&#8217;,<br \/>\n    success:function (txt) {<br \/>\n       $(&#8216;#&#8217;+$pDivID).html(txt);<br \/>\n    }<br \/>\n});<br \/>\n<\/textarea><\/p>\n<p>Server-side check.php<br \/>\n<textarea name=\"code\" class=\"php\"><br \/>\n<?php\nif ($vAvailable) {\n  echo 'Congrats! Your username is available';\n} else {\n  echo 'Sorry! Your username is not available';\n}\n?><br \/>\n<\/textarea><\/p>\n","protected":false},"excerpt":{"rendered":"<p>HTML Checking&#8230; JavaScript $(&#8220;#loading&#8221;).hide(); var orig=$(&#8220;#loading&#8221;).html(); $(&#8220;#UserNameInputID&#8221;).blur(function() { $(&#8220;#loading&#8221;).html(orig); $(&#8220;#loading&#8221;).show(); loadTextPage(&#8220;loading&#8221;,&#8221;check.php?username=&#8221;+$(&#8220;#UserNameInputID&#8221;).val()); }); \/** load a text page into this div *\/ function loadTextPage($pDivID,$pURL) { $.ajax({ url:$pURL, dataType:&#8217;html&#8217;, success:function (txt) { $(&#8216;#&#8217;+$pDivID).html(txt); } }); Server-side check.php<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,12,21],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/195"}],"collection":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=195"}],"version-history":[{"count":0,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}