在php中使用Jquery手风琴,但调用动态php脚本onclick

Here is the code I have currently,

<div class="panel">
    <?php
    if(isset($Uniid)) {
        if (isset($from)) {
            $url='Inevent.php';
            include("display$category.php");
        }
    }
    ?>
</div>          


<script>
document.addEventListener("DOMContentLoaded", function(event) {
    var acc = document.getElementsByClassName("accordion");
    var panel = document.getElementsByClassName('panel');
    for (var i = 0; i < acc.length; i++) {
        acc[i].onclick = function() {
            var setClasses = !this.classList.contains('active');
            setClass(acc, 'active', 'remove');
            setClass(panel, 'show', 'remove');

            if (setClasses) {
                this.classList.toggle("active");
                this.nextElementSibling.classList.toggle("show");
            }
        }
    }
    function setClass(els, className, fnName) {
        for (var i = 0; i < els.length; i++) {
            els[i].classList[fnName](className);
        }
    }
});
</script>

The main class which is the accordian is displayed currently, but when I click on the accordian, is when I want the panel to be executed, how do I go about doing it.

You can out your php code in a separate file and then call it with AJAX.

If you name your php file "loadPanel.php" then the AJAX request would look like this:

$.ajax({
  url: "loadPanel.php"
}).done(function(response) {
  $( '.panel' ).html( response );
});

Then add whatever php code you want inside you panel div to the loadPanel.php file.

The documentation for ajax is on the jQuery site here: http://api.jquery.com/jquery.ajax/.

There is a solution that isn't well known, but very powerful that consist in updating a part of the page with jQuery (works with the latest version of jQuery). So, to do that, you don't even have to create another page, so you just have to use the jQuery load() function. This method is the simplest way to fetch data from the server. It is roughly equivalent to $.get(url, data, success) except that it is a method rather than global function and it has an implicit callback function. When a successful response is detected (i.e. when textStatus is "success" or "notmodified"), .load() sets the HTML contents of the matched element to the returned data. This means that you can use this method like this:

$( ".panel" ).load( window.location.href );