I want return true if data is empty or false if data is not empty.If data is empty continue with form action else stay in current page.
Code is:
<script type="text/javascript">
    function error()
    { 
        var response = false;
        $.ajax({
            url: BASE_URL + 'auth/validateForm',
            type: 'POST',
            data: {
                surname: $("#r-surname").val()
            },
            dataType: "json",
            success: function(data) { 
                if(data.surname)
                { 
                    $('#error_surname').html(data.surname);
                    response = false;
                }else{
                    $('#error_surname').html('');
                    response = true;
                }
            },
            error: function(data) { 
                        return false;
            }
        });
        alert(response);
            return response;
    }
</script>
<form action="{$BASE_URL}contul-meu" method="post" name="registration" onsubmit="return error()">
                        <table>                              
                            <tr>
                                <td>
                                    <label for="r-surname">Prenume*</label>
                                </td>
                                <td>
                                    <input type="text" class="text" id="r-surname" name="surname"  value="{$user['surname']}"/>
                                </td>
                                <td><small id="error_surname" class="err"></small></td>
                            </tr>
                        </table>
 </form>
php:
public function validateForm()
{
    $surname = $this->input->post('surname');
    $data = array();
    if(strip_tags($surname) == '')
    {
        $data['surname'] = 'Prenumele este invalid!';
    }
    echo json_encode($data);
}
var response is only false.How make response true if no error?
 
     
     
    