Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append a php file with jquery

i have a file which echoes out data from a database.

I wish to have a load more button which appends this file so that it will keep loading the rest of the results.

The php page works fine but need help with the jquery...

have used this else where for a json return but dont think this is needed for this.

So i am trying this:

$(document).ready(function(){
$("#loadmore").click(function () {
     $("#content").append('includes/loadmorebuilds.php');
});
});

In essence, this works but it appends 'includes/loadmorebuilds.php' as just that. I simply appends those words and not the file.

Any help on this?

Many thanks!

like image 640
craig Avatar asked May 23 '26 09:05

craig


1 Answers

You could use $.ajax to get content from file to be appended into DOM. One important thing is that you should use Relative PATH to your web root on url parameter in $.ajax

So it will become like this

$('#loadmore').click(function() {
    $.ajax({
       url: '/relative/path/to/your/script',
       success: function(html) {
          $("#content").append(html);
       }
    });
});

And make sure you should be able to access your script on http://www.example.com/relative/path/to/your/script

like image 93
pveyes Avatar answered May 26 '26 01:05

pveyes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!