troubleshooting Question

Mockjax for php script is always getting the worng value

Avatar of Ashraf Hassanein
Ashraf Hassanein asked on
12 Comments1 Solution937 ViewsLast Modified:
I am using the Jquery validation plugin to validate the username format, however I want to add an extra step to validate if the user already exists in the data base or not,
   So I have created the following php script (Which is working pretty well):
if(isset($_POST['username']) && !empty($_POST['username'])){
      $query="select username from users where username='".$username."'";
      $res=pg_exec($con, $query);
      $count= pg_num_rows($res);
      if($count > 0){
        $HTML='Username is not available';
        $HTML='Username is available';
      $HTML='Please enter a username';
  echo $HTML;

And I have created the following mockjax script:
        $(document).ready(function() {
                                url: "useravailable_check.php",
                                type: "POST",
                                response: function(settings) {
                                          var username =,
                                          response="Username is not available";
                                          this.responseText = "true";
                                          if(response!='Username is available'){
                                                this.responseText = "false";
 And below is the validator :
                var validator = $("#createuser").validate({
                        rules: {
                                 username: {
                                        required: true,
                                        minlength: 6,
                                        remote: "useravailable_check.php"
                             messages: {
                                   username: {
                                        required: "Enter a username",
                                        minlength: jQuery.format("Enter at least {0} characters"),
                                        remote: jQuery.format("{0} is already in use")
       But I am getting always back that the user is available, is there anything wrong in the mockjax function I have?
Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros