Skip to content
Advertisement

How to insert contents from AJAX result into an element without removing its existing contents?

I’d like to first point out that english is not my first language and im a newbie tryna learn news things so i apologize if i might sound confusing.

So here it goes, im trying to make an image viewer for my local image files and i decided to try and make a “load more” button using jquery/ajax & php so it doesn’t show all the files on the selected directory.

Here’s my process.php:

JavaScript

My jQuery/Ajax:

JavaScript

I manage to get the data i needed for each ajax load/loop using those codes however, i really can’t figure out how to ouput all those formatted data/images on the array that was created from process.php into the #imgViewerContainer element.

The ajax load/result looks like this:

JavaScript

Basically, on page load the target element have contents and looks like this:

JavaScript

So i need to insert each ajax results inside & at the bottom of #imgViewerContainer element. I decided to try and use append() & html() and got this error:

Uncaught TypeError: Failed to execute ‘appendChild’ on ‘Node’: parameter 1 is not of type ‘Node’.

Any help, guide or explantion is greatly appreciated. Thank you!

Advertisement

Answer

you get error in append because the data.imgs is array

in process.php change this:

JavaScript

to this:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement