Home > Net >  Uncaught TypeError: $.ajax is not a function in jquery post function of laravel project
Uncaught TypeError: $.ajax is not a function in jquery post function of laravel project

Time:12-16

i try to use jquery to fetch database data in real time . here is code

  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X 965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH 8abtTE1Pi6jizo" crossorigin="anonymous"></script>

  
        <script>
        $(document).ready(function () {
                   
                  

         $('#ref_name').on('keyup',function() {
                var ref_id = $('#ref_name').val();
                var token = "{{csrf_token()}}";
               
                $.ajax({
                    type: "POST",
                    url:"{{route('get.ref.id')}}",
                    data:{
                        'ref_id': ref_id ,
                        '_token' : token
                    },
                    success:function(data){
                        $("#ref").html(data);
                       }
                     );
                 });

             });
        </script>

here is controller code in laravel .

 public function getRefId(Request $request)
    {
        $id = User::where('username', $request->ref_id)->first();
        if ($id == '')
        {
            return "<span class='help-block'><strong style='color: #f90808'>Referrer Name Not Found</strong></span>";
        }else{
            return "<span class='help-block'><strong style='color: #1ed81e'>Referrer Name Matched</strong></span>
                    <input type='hidden' id='referrer_id' value='$id->id' name='referrer_id'>";
        }
    }

the error is

Uncaught TypeError: $.ajax is not a function

I checked jquery code . i not see where is problem . can someone help me where is issue .

thanks

CodePudding user response:

It's because you are using the slim package which doesn't have the ajax function. Try to use minified version instead: https://code.jquery.com/jquery-3.6.2.min.js

  • Related