We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16313
    • 71 Posts
    I need to make choice the city with refresh content without reload the page.
    When city choosen, I replace content for the slideshow in jquery, and run the snippet:
    $('#slider_wrapper').replaceWith('<div id="slider_wrapper">[[!slider?&city=`'+$(this).text()+'`]]</div>'); 

    but snippet does not see jquery variable $city
    Another strange happens. Snippet does not see the variable $ city, but echo $city displays the name of the city.

    When I send to snippet the city as a text value, all works fine. But I’d like do it dynamicaly.
    $('#slider_wrapper').replaceWith('<div id="slider_wrapper">[[!slider?&city=`London`]]</div>'); 


    I tried did it via cookie, save cookie in jquery and open it in snippet. But snippet does see new cookie value only after page reloaded.
    Could anybody help me?
    I use revo 2.0.8
      • 33968
      • 863 Posts
      You cannot run a snippet after the page has already loaded... they are parsed and executed on the server and only html/jscript is sent to your browser.

      If you want to do this dynamically, you’ll have to place your snippet in an external file or document and load it in via ajax.

      What does the snippet do exactly? I might be able to suggest an alternative smiley
        • 16313
        • 71 Posts
        Quote from: lucas at May 22, 2011, 05:48 AM

        You cannot run a snippet after the page has already loaded... they are parsed and executed on the server and only html/jscript is sent to your browser.

        If you want to do this dynamically, you’ll have to place your snippet in an external file or document and load it in via ajax.

        What does the snippet do exactly? I might be able to suggest an alternative smiley
        Thanks for your answer Lucas!
        it selects resources with images dependence selected tv city, put them to jquery slider and then reload this slider.
          • 33968
          • 863 Posts
          Probably ajax is the way to go - but as always, there may well be a better way.

          You’ll need to create a new resource with a blank template where you will place your snippet call to receive the ’city’ parameter. Change your slider snippet to receive the parameter via $_GET.

          Seeing you’re already using jQuery, your Ajax code could be something like this:
          $.ajax({
             type: "GET",
             url: "[[~30]]",         <---- link to resource containing [[!slider]] snippet
             data: "city="+$(this).text(),          <--- setup your script to insert the city name here
             success: function(html) {
               $('#slider-wrapper').replaceWith(html);
             }
          });
          

          Obviously you’ll need to assign that to an event so that the code fires when a new city has been selected.

          More about jQuery’s ajax() function here.

          Note that it’s not going to do anything if the user has js disabled.
            • 16313
            • 71 Posts
            Thanks buddy!
            it works like a charm smiley
            gone read the documentation by Ajax grin