A
A
Alexander Tishchenko2020-12-30 21:37:36
MySQL
Alexander Tishchenko, 2020-12-30 21:37:36

Loading data with AJAX in CodeIgniter?

Hello.
I need help, I searched the Internet and did not find what exactly I need.
Articles are loaded on my site, There are a lot of them, so I don’t know how to do this:
EXAMPLE:
The last 10 articles are loaded. At the end (at the bottom) there is a button, when clicked, 10 more articles should be loaded, etc.
PS
They will have to be loaded using AJAX.
I am using CodeIgniter.
Thank you all in advance...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Kulaxyz, 2020-12-30
@Kulaxyz

I'll tell you how I did it myself:
An ajax request is sent when you click on a button with one parameter: the id of the last article. It can be stored as data-id for each article and retrieved, for example, as last-child.
On the server:
Method pulling articles from the database, where the request is by type
Then you render the code itself, I did it on Laravel, there is a built-in function for this. I don't know if there is something similar in CI. In extreme cases, you can simply form a string:

$text= '';
foreach($articles as $article) {
    $text.="<a href='/articles/$article['id']'>$article['title']</a>"
}

And so on, all the required fields.
After that, we return the data and in js add html to the desired block (the parent of all articles) via append.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question