Hide image when loading page through onchange function

1

Hello friends, I have the following code to show the image when the page loads when doing POST by means of a select:

this is the image:

<img src="img/icons/loader_transp.gif" width="20px" id="searchingimageDiv" class="img_loading" style="display:none">

this code of the select post:

$(document).ready(function(){
            $("#Div2").change(function(){
                $.ajax({
                    url:"../../../controllers/mi.php",
                    type: "POST",
                    data:"V="+$("#Div2").val(),
                    success: function(opciones){
                        $("#div_view").html(opciones);

                    }
                })
            });
        });

this is the code to show the image:

  $(window).load(function(){
      $('#Div2').on("change", function(){
         $('#searchingimageDiv').toggle();
      });
   });

The problem comes after doing the post, the image shows it, but it does not hide automatically when I finish loading the page, which I may be doing wrong, some suggestion

Thank you.

    
asked by Alexander Quiroz 02.08.2017 в 18:25
source

2 answers

1

Can it serve you like that?

$(document).ready(function(){
            $("#Div2").change(function(){
                $.ajax({
                    url:"../../../controllers/mi.php",
                    type: "POST",
                    data:"V="+$("#Div2").val(),
                    success: function(opciones){
                        $("#div_view").html(opciones);
                      $('#searchingimageDiv').toggle();
                    }
                })
            });
        });
    
answered by 02.08.2017 / 18:38
source
0

Hello Alexander, if what you want to do is hide the image when loading the page you should place this code in the same document ready $ ("# searchingimageDiv"). hide ():

$(document).ready(function(){
$("#Div2").change(function(){
    $.ajax({
        url:"../../../controllers/mi.php",
        type: "POST",
        data:"V="+$("#Div2").val(),
        success: function(opciones){
            $("#div_view").html(opciones);

        }
    })
});
$("#searchingimageDiv").hide();});

If you need to do otherwise, tell us more about your problem so we can help you.

    
answered by 02.08.2017 в 18:43