@Twitt2018-04-07 16:15:37
Web development
@Twitt, 2018-04-07 16:15:37

AJAX Pagination, what to get in response, JSON or HTML?

I myself answer the back, but I work in conjunction with the front-end, the task is to make AJAX pagination. Those. the user presses the button "show more X products", and they are loaded to him. We had a dispute about how best to give me the data to him.
His point of view: he sends an AJAX request, and I return the HTML code of the next page to him, and he receives it and inserts it into the page
My point of view: he sends an AJAX request, I return the data to him in JSON, he parses it, and inserts it into the page .
Who is right and why?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Insolation, 2018-04-07

I didn’t work with the back, but logically JSON is better, and let it parse it and generate html markup (this is the essence of the front - send a request, accept a response, and make a view from the response)
The back is not created in order to return HTML markup.

Oleg, 2018-04-07

If you do not have a SPA, then it is logical to give HTML to the server, it still does it for regular requests, what's the difference AJAX or not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question