I make a request:

jQuery(document).on('click', '.trigger',function(e) { e.preventDefault(); var that = jQuery(this); var event_link = that.data('link'); var url = '/' + event_link; jQuery.post(url, function(data) { console.log("++"); }).done(function (data) { console.log(data); }).fail(function (data) { console.log("---"); }) });` 

The controller pulls the base, the base returns an array. I convert the array to json in data .

Question: how now to show this good in the view? If without ajax, the controller gives the array an array, which we loop through and embed in the code. How to be here? Is it possible to get an array of php or how to correctly embed the data in html?

    1 answer 1

    Why do you give the data to Ajax? Send immediately to the view, if you received data through Ajax, then process it through JS because the view will not process it, since it has already been output so that the view can process the data, load it again, for example, refresh the page. Or did I not understand something? If you just need to embed the data into the page and do not reload, then give the ready html and embed it

    • Situation FIFT FIFT. Or I generate all html in the controller and give it away. Or through js it turns out to construct? - Dmitry Berezhnoy
    • Well, as if I myself answered ... either this or that, both approaches are normal, and the choice of a specific one depends on a specific task from the point of consideration of following the adopted architecture in the project - AlexandrX