0

I'm using magnificient popup on my website, and I would like to execute ajax function when a link is clicked and the result of the query should be the content od the popup.

this is my code (I'm pretty new in JQuery) :

<script>
  function showPics(str)
  {
    if (str=="")
    {
      document.getElementById("displayPics").innerHTML="";
      return;
    } 

    xmlhttp=new XMLHttpRequest();

    xmlhttp.onreadystatechange = function()
    {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
        document.getElementById("displayPics").innerHTML=xmlhttp.responseText;
      }
    }

    xmlhttp.open("GET","getpics.php?q="+str,true);
    xmlhttp.send();
  }
</script>

<a class="1-popup" href="#">Guerlain</a>

<script type="text/javascript">
    $('a').click(function() {
        showPics($(this).attr('class').charAt(0)), //Ajax function call
        $(this).magnificPopup({ //Popup call
            type:'inline',
            midClick: true,
            closeBtnInside:true
        });
    });
</script>

<div id="displayPics"><b>Pictures will be listed here.</b></div>

The content is loaded, but the popup not.

mishik
  • 9,973
  • 9
  • 45
  • 67

1 Answers1

0

Here's the solution of my issue :

<a class="1-popup" href="#displayPics">Guerlain</a>

<script type="text/javascript">
    $('a').click(function(){
        showPics($(this).attr('class').charAt(0)) //Ajax function call
    });
</script>

<script type="text/javascript">
    $('a').magnificPopup({ //Popup call
        type:'inline',
        midClick: true,
        closeBtnInside:true
    });
</script>

<div id="displayPics" class="white-popup mfp-hide"><b>Pictures will be listed here.</b></div>

Thank you all.