CodeIgniter Forums
Newbi ajax question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Newbi ajax question (/showthread.php?tid=78882)



Newbi ajax question - fzamaan - 03-22-2021

Hi all,

i have a basic question.

i am building a shopping cart site. 
in the products page, my plan is to load the product using ajax and pagination.
for this i am calling the ajax to pull the records (limit 10,1) on page load event.
now i am getting the result set from controller to view. 

my doubt is, where i should format this received data to form a html/css formated products table?
should i format it within the model or controller before receiving the data to view?

* the ajax response is placed in a div called "products_wrapper"

Please advise.


RE: Newbi ajax question - includebeer - 03-23-2021

You can return the view (html) to your ajax request and just add that chunk of html to your document.
What I prefer is to only return json data and the front end (javascript) add the data to the html document.


RE: Newbi ajax question - fzamaan - 03-24-2021

(03-23-2021, 02:22 PM)includebeer Wrote: You can return the view (html) to your ajax request and just add that chunk of html to your document.
What I prefer is to only return json data and the front end (javascript) add the data to the html document.

Thanks. so i am returning the products via a db query from model to a controller through ajax.
then from controller i load a view (data.php). that page content is the ajax response and i printed the response to a div.
so jason involved here. what i am doing is ok?


RE: Newbi ajax question - manager - 03-24-2021

(03-24-2021, 12:06 AM)fzamaan Wrote: Thanks. so i am returning the products via a db query from model to a controller through ajax.
then from controller i load a view (data.php). that page content is the ajax response and i printed the response to a div.
so jason involved here. what i am doing is ok?
From your product page make ajax call to the controller, controller get all data from some model which is making db query to retrive data, and after all controller returns json data (or ready html view data) to your ajax as a response. All you need is append this response to your pages some place on ajax completion


RE: Newbi ajax question - fzamaan - 03-24-2021

(03-24-2021, 10:42 AM)manager Wrote:
(03-24-2021, 12:06 AM)fzamaan Wrote: Thanks. so i am returning the products via a db query from model to a controller through ajax.
then from controller i load a view (data.php). that page content is the ajax response and i printed the response to a div.
so jason involved here. what i am doing is ok?
From your product page make ajax call to the controller, controller get all data from some model which is making db query to retrive data, and after all controller returns json data (or ready html view data) to your ajax as a response. All you need is append this response to your pages some place on ajax completion

Thanks. Looks like how i am started doing is correct.


RE: Newbi ajax question - includebeer - 03-28-2021

(03-24-2021, 12:06 AM)fzamaan Wrote:
(03-23-2021, 02:22 PM)includebeer Wrote: You can return the view (html) to your ajax request and just add that chunk of html to your document.
What I prefer is to only return json data and the front end (javascript) add the data to the html document.

Thanks. so i am returning the products via a db query from model to a controller through ajax.
then from controller i load a view (data.php). that page content is the ajax response and i printed the response to a div.
so jason involved here. what i am doing is ok?

Yes that looks ok. Sorry for the late reply, I didn't receive any email from the forum...


RE: Newbi ajax question - fzamaan - 03-31-2021

no problem, Thanks guys.