3

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!

1
  • You're now appending #content with the string 'includes/loadmorebuilds.php'. If you want to fetch the file itself I'd suggest you use .load() to fetch the file asynchronously Commented Oct 3, 2013 at 21:44

3 Answers 3

6

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

Sign up to request clarification or add additional context in comments.

3 Comments

This amongst others works. However it only works if i change my loaded file to something simple e.g. a php echo with a word. Its not working my query etc on it... anything i need to change?
try using var_dump(); on query result then exit; and see what you got. Your query might be returning NULL values or there's an error on your code. You could access the script directly via URL or AJAX calls.
the thing is, if i try do a simple php include of the file then everything loads fine... :/
3

You have two options:

$('#content').load('includes/loadmorebuilds.php');

Which will replace the content of #content with the new html.

Or this:

$.ajax({
    url: 'includes/loadmorebuilds.php'
}).done(function(data) {
    $('#content').append(data);
});

Which will append the new data.

Comments

2

use $.ajax

$(document).ready(function(){
        $(".loader").click(function(){

      $.ajax({
                url:"index.php",
                dataType:"html",
                type:'POST', 

                beforeSend: function(){
                },
                success:function(result){
                      $(".content").append(result);
                 },

        });
    });
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.