jquery Validation engine. Ajax error 200 parsererror

2.1k Views Asked by At

im trying to use the ajaxNameCallPhp to check if a username already exists in my database. I have never used this before so im struggling to get it working. When I input a username that already exists into my username field it just shows "Validating, please wait". Looking at firebug I can see an Ajax error: 200 parsererror being displayed.

Code snippet from members.php

userName: {
                    title: 'User Name',
                    list: false,
                    width: '15%',
                    inputClass: 'validate[required,custom[onlyLetterNumber],maxSize[20],ajax[ajaxNameCallPhp]]'
                },
                FirstName: {
                    title: 'First Name',
                    width: '20%',
                    inputClass: 'validate[required]'
                },
                LastName: {
                    title: 'Last Name',
                    width: '20%',
                    inputClass: 'validate[required]'
                },
                password: {
                    title: 'Password',
                    list: false,
                    type: 'password',
                    width: '20%',
                    inputClass: 'validate[required]'
                },

The validation on other fields works fine just the userName fails.

jquery.validationEngine-en.js

"ajaxNameCallPhp": {
                    "url":"ajaxValidateFieldName.php",
                    "alertText": "* This name is already taken",
                    "alertTextLoad": "* Validating, please wait"
                },

my ajaxValidateFieldName.php:

<?php
include('dbConnect.php');

/* RECEIVE VALUE */
$validateValue=$_REQUEST['fieldValue'];
$validateId=$_REQUEST['fieldId'];


$validateError= "This username is already taken";
$validateSuccess= "This username is available";



    /* RETURN VALUE */
    $arrayToJs = array();
    $arrayToJs[0] = $validateId;


$sql_checkusername = "SELECT userName FROM tiptop_user WHERE userName = '$validateValue'";
$result=mysql_query($sql_checkusername );
$count=mysql_num_rows($result);

if($count=0){
$arrayToJs[1] = true; // RETURN true
echo json_encode($arrayToJs); // RETURN ARRAY username is available
} 

else {

for($x=0;$x<1000000;$x++){
if($x == 990000){
$arrayToJs[1] = false;
echo json_encode($arrayToJs);
}
}
}
?>

When I debug I can see that count = 1 and the following is returned: ["AndAda52",false]. Appologise I have never used this function before

1

There are 1 best solutions below

0
On

ajaxValidateFieldName.php file needed to be in the same directory as the validateEngine script files. If statement in the ajax file needed changed from (if($count=0)) to (if($count==0))