Welcome Guest, Not a member yet? Register   Sign In
Newbi ajax question
#1

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.
Reply
#2

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.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#3

(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?
Reply
#4

(This post was last modified: 03-24-2021, 10:45 AM by manager.)

(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
Reply
#5

(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.
Reply
#6

(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...
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#7

no problem, Thanks guys.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB