1

I made an ajax request as below, but the request but it's not running. So I tried to 'console.log' but it's not working.

                    <input type="text" class="form-control" id="search">
                      <table class="table table-hover">

The above is the input field and below is the script tag.

<script type="text/javascript">
                    
                    var base_url = "<?php echo base_url(); ?>";
                    
                      $(document).ready(function(){
                          
                        $("#search").keypress(function(){
                            console.log('ko') //this console is running
                          $.ajax({
                              console.log('ko') //this console is not running
                            //   url:"<?php //echo base_url( 'Parts/search')?>",
                              type:'POST',
                              data:{
                                name:$("#search").val(),
                                },
                                
                            success:function(data){
                              $("#output").html(data);
                             
                            }
                          });
                        });
                      });
                    </script>
  • 1
    You can't console.log inside ajax property – Fajar Alam Rahmat Sidik Aug 16 '22 at 06:36
  • Any suggestions on how to unit test the ajax request since it is giving issues and I would like to know where. – Leakey Braxton Aug 16 '22 at 06:40
  • 1
    I'm still learning too, so please don't expect to much from me. but can you tell us the issue? is there any response from that url? usually when i play with ajax, I always open developer tools on the browser, and go to the tab network. – Fajar Alam Rahmat Sidik Aug 16 '22 at 06:46
  • Okay @FajarAlamRahmatSidik, so I opened the developer tool and used it to test the lines up to the ajax request as indicated above. The problem is, The information given in the input field above does not get passed into the ajax request in order to be store in the object data{}. – Leakey Braxton Aug 16 '22 at 06:58
  • well, make it simple first. remove the data property. just send the url, and in the url just var_dump("ajax is connected"). If it's connected, then the error is not in the ajax, maybe it's the data property. try to console.log($("#search").val()) before the ajax. – Fajar Alam Rahmat Sidik Aug 16 '22 at 07:18
  • It helped me establish where the problem was and I managed to rectify it. Much appreciated @FajarAlamRahmatSidik. – Leakey Braxton Aug 17 '22 at 04:55

0 Answers0