Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading