I have some code that validates a form using Prototype but I want to add a jQuery ajax function to check if the username already exists in the database. However, the value being returned by jQuery is always an object and not the boolean of whether the username exists or not. Here is my code so far:
validation.js
//Using Prototype
Validation.addAllThese([
['validate-username', 'Username already exists. Please choose another one.',
function (v) { //v is the value of the username field in the form.
//Using jQuery
var match = jQuery.ajax({
url: "/php/ajax/check_username_exists.php",
data: {username: v},
async: false
});
return (match.responseText == v);
]);
check_username_exists.php
<?php
include '../library.php';
include '../config.php';
//Echo string username if matches
echo select_row("USERNAME", "members", "USERNAME='".$_GET['username']."'");
?>
I have checked other threads on StackOverflow including this one but none seem to fix the problem.
Thanks