How to use the Jquery validate plugin's remote function

I’m trying to use the Jquery validate plugin’s remote function to check that a username is not already in use. But it doesn’t seem to be making it to the php. I have tried changing the path. Right now the form is located in the main directory with the validate file in a js folder and the php in a scripts folder.

Here is my js:

	rules: {
                    minlength: 2,
	        		required: true,
                    remote: "scripts/check_username.php"
	    messages: {

	      username: {
	        minlength: "username must be at least 2 characters",
	        required: "Enter a username ",
	        remote: jQuery.format("{0} is already in use")
	    highlight: function(label) {
	    success: function(label) {

php - scripts/check_username.php

require_once 'app_config.php';
require_once 'database_connection.php';

    $username = mr_clean($_POST['username']);
    //echo "email: ".$email;

    $query = sprintf("select * from users where username = '%s';", $username);

    $result = mysql_query($query) or handle_error(mysql_error());
    $num_rows = mysql_num_rows($result);

    if($num_rows == 0)
        echo "true";  //good to register
        echo "false"; //already registered
    echo "false"; //invalid post var


Have you inspected the AJAX request using FireBug (or any other tool)?

  • Is it being sent?
  • What are the parameters?
  • What is the response?

At first sight, there doesn’t seem to be anything wrong with your code, that’s why I’m asking the questions above.