Reload variable within a div?

1

I have a search engine that depending on how you fill it, a button or another should appear, the idea is that if I do not enter one of the filters / fields of the search engine, the search button will go black, I'll leave it as I did:

                    <div class="searchsubmit-wrapper">
                    <div class="submit-main-button">
                        <div id="divevento">
                        {if $selectedCat == false}
                            Selecciona almenos dos filtros
                        {else}
                        <div class="searchsubmit2">{__ 'BUSCAR'}</div>
                        <input type="submit" value="{__ 'BUSCAR'}" class="searchsubmit">
                        {/if}
                        </div>
                    </div>
                </div>

and here I leave the variable:

{var $selectedCat = isset($_REQUEST['category']) && $_REQUEST['category'] != "" ? $_REQUEST['category'] : ''}

if selectedCat has no value, I want the "select two filters" message to appear. Once it works, I'll change it to the submit but it will be gray and not selectable.

and if selectedCat has value I want the submit button to appear fine.

So far everything goes well, the problem is that I need to update the value of this variable without having to reload the page and I have been looking for and trying to try things but I think that I do not approach what I want and I do not have idea of ajax .

    
asked by dev 12.09.2016 в 18:28
source

1 answer

1

Check the web inspector which is what the server restores, so I see it will not be possible without refreshing the page, or use ajax to show what you want.

This would be what the web inspector would show (f12)

<div id="divevento">
    Selecciona al menos dos filtros
</div>

With a request ajax you could consult the variable to the server and this way you would avoid refreshing the whole page

NOTE: This is using jQuery

$.ajax({
  url: "url_de_la_variable",
  data: "si es necesario enviamos algo",
  success: function(data){
    //recibimos toda la información de la variable
    if(data[0].selectedCat=="true"){
      //.html() reemplazaría el texto del div y lo sustituiría por lo que le pongas dentro de .html("")
      $('#divevento').html(
        '<div class="searchsubmit2">info_data</div>'+
        '<input type="submit" value="info_data" class="searchsubmit">'
      );
    };
  },
  error: function(objXMLHttpRequest){
    console.log(objXMLHttpRequest);
  }
});
    
answered by 12.09.2016 / 19:00
source