0

I am using this function to check the username availability type function in laravel framework-

<script type="text/javascript">
    $(document).ready(function() {
        $("#clanname").keyup(function(e) {

        var clanname = $(this).val();
        if(clanname.length < 4){$("#user-result").html('');return;}

        if (clanname.length >= 4) {
            $("#user-result").html('<img src="images/ajax-loader.gif" />');
            $.post('/Myclan/checkClanname', {'clanname':clanname}, function(data) {
               console.log(data);
            });
        }
        });
    });
</script>

which calls the controller Myclan/checkClanname -

public function checkClanname() {
        $clanCount = Clan::where('clanname', '=', Input::get('clanname'))->count();
        if ($clanCount == 0) {
            return true;
        } else {
            return false;
        }
    }

but I am getting an error popup

Nikunj Kumar
  • 306
  • 6
  • 18
  • `Boolean` is not proper html content. Try returning text like "Free"/"Taken" and check. If you want to pass data structures use `JSON`. – Michał Mar 20 '14 at 12:07
  • This may help when you want to call a php function using ajax http://stackoverflow.com/questions/2269307/using-jquery-ajax-to-call-a-php-function – AdRock Mar 20 '14 at 12:13
  • still getting the same error apopup with message 'object not found' . – Nikunj Kumar Mar 20 '14 at 12:13
  • Why is this tagged Laravel and your url is `/Myclan/checkClanname.php`? Seems like a plain and simple PHP file, not Laravel. Is your javascript being able to find this script? Try to use the full url to check. – Antonio Carlos Ribeiro Mar 20 '14 at 12:18
  • sorry It was /Myclan/checkClanname where 'Myclan' is the controllername and 'checkClanname' is the action or function inside that controller – Nikunj Kumar Mar 20 '14 at 12:21
  • Can you post the relevant routes for that? – user1669496 Mar 20 '14 at 13:06

1 Answers1

0

Try

$clanCount = Clan::where('clanname', '=', Input::get('clanname'))->get()->count();
clod986
  • 2,527
  • 6
  • 28
  • 52