Loading Content using Ajax with PHP Include

前端 未结 5 1204
旧时难觅i
旧时难觅i 2021-01-28 18:15

I have a PHP page which has a div, the div has a PHP includes which includes this file:



        
相关标签:
5条回答
  • 2021-01-28 18:43

    Use this instead of your code

    var page = 1;
    $(document).on('click','.Button',function(){
    
        $("#posts").load("miniBlog.php", function(response, status, xhr) {
            if (status == "error") {
                var msg = "Error!: ";
                alert(msg);
            }
        });
        page++;
    });
    
    0 讨论(0)
  • 2021-01-28 18:50

    Don't call the function in the click method parameter. You have to put the reference to the handler function.

    var handler = function onClick () {...}
    
    $("whatever").click(handler);
    
    0 讨论(0)
  • 2021-01-28 18:57

    Content dose not look too huge.Can't you just hide div (with content already present in it)& show it onclick.

    0 讨论(0)
  • 2021-01-28 18:59

    You are not able to see content loaded by AJAX because the page is reloading as soon as you click the anchor. Disable the anchor event by using preventDefault() and this should fix it.

    <script type="text/javascript">
        var page = 1;
        $(document).on('click','.BlogButton',function(e){
    
            // stop page from reloading
            e.preventDefault();
    
            $("#posts").load("miniBlog.php", function(response, status, xhr) {
                if (status == "error") {
                    var msg = "Error!: ";
                    alert(msg);
                }
            });
            page++;
        });
    </script>
    
    0 讨论(0)
  • 2021-01-28 19:03

    Change your code to

    var page = 1;
    
    $(document).ready(function(){
         $(".Button").click(onClick);
         onClick();
    };
    
    0 讨论(0)
提交回复
热议问题