Refresh DOM with jquery after AJAX call

前端 未结 2 1981
面向向阳花
面向向阳花 2021-01-15 02:04

I\'m working on a new project http://www.hotwirerevealed.com which reveals / identifies hotels on hotwire.com. After inputting a state and a destination I have a javascript

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-15 02:26

    Just to be clear, $("#details").html(data) loads the "a" tags right?

    Last time I checked, fancybox() requires the element to be already existing on the DOM. When $(document).ready fires, the $(".hotel") probably doesn't exist yet. You can move the fancybox setups after $.post like:

    function post(){
      $.post("lookup.php", 
        {action: "find", area: area, stars: stars, amenities: amenities, state:
          $('#state').val()}, 
        function(data) { 
          $("#details").html(data);
          // bind fancy box
          $(".hotel").fancybox({
            'width'             : '75%',
            'height'            : '75%',
            'type'              : 'iframe'
          });
      });
    }
    

    You might have to watch out for calling fancybox to elements that have been called with fancybox already. There might be some complications there.

提交回复
热议问题