ajax in at the first load of page in php

rsbypi4

New member
1742035050371.pngAs you can see I have a page, the problem is every time to load this page the footer goes up and as you can see its show blank space or empty space in the lower part of my page. Actually, I have code for ajax that if the textbox is empty or wrong input, it shows html code there. But in that situation my code running properly. here's the sample output of my page.
1742036082537.pngMy problem is every time my page load at the 1st time my ajax code is not working properly and here my code.
JavaScript:
<script type="text/javascript">/*for search*/
         $(document).ready(function(){
            $("#form3Name").keyup(function(){
               var input = $(this).val();

               if(input != "")
                  {
                     $.ajax({
                     url:"search",
                     method:"POST",
                     data:{input:input},

                     success:function(data){
                       
                        $("#searchresult").html(data);
                     }
                 
                     } )
                  }
               else if(input == "")
               {
                  //header("refresh: 1;");
                  //$("#searchresult").css("display","none");

                  $.ajax({
                     url:"search_empty",
                     method:"POST",
                     data:{input:input},

                     success:function(data){
                       
                        $("#searchresult").html(data);
                     }
                     } )
               }
            });
         });
       
      </script>
1742036621841.png if I input correct data or wrong data in textbox the ajax code is working properly. But during at the 1st time or if you call this page at the 1st time, the code of ajax is not working even the textbox is empty. So, I don't know what my problem in my code.
 
Good day, I already solve my problem., I update my code in script only.
JavaScript:
<script type="text/javascript">
         $(document).ready(function(){
            $.ajax({ //ready to display while textbox is empty
                  url:"search_empty",
                  success:function(data){
                    
                     $("#searchresult").html(data);
                  }
                  } )

            $("#form3Name").keyup(function(){
               var input = $(this).val();
               if(input != "")
                  {
                     $.ajax({
                     url:"search",
                     method:"POST",
                     data:{input:input},

                     success:function(data){
                        
                        $("#searchresult").html(data);
                     }
                  
                     } )
                  }
               else
               {
                  //header("refresh: 1;");
                  //$("#searchresult").css("display","none");

                  $.ajax({
                     url:"search_empty",
                     method:"POST",
                     data:{input:input},

                     success:function(data){
                        
                        $("#searchresult").html(data);
                     }
                     } )
               }
            });
         });
        
      </script>
 
Back
Top