Welcome Guest, Not a member yet? Register   Sign In
HTML in Model
#4

(09-25-2019, 11:35 PM)AngelTrader Wrote: I agree, and it was my gut feeling that no HTML should be in model .... unfortunately I have no idea where to start since when I call the model/function , it will return only JSON data, then where do I get my formatting from.

Normally when you run an AJAX call you have the "success" handler in which you just print the result like $('#mydiv').html(data) where "data" contains the full rendered HTML with values , but since I can't use HTML in the model , where do I get that from then.

Sorry, i'm totaly confused

Most often the AJAX is returning data to an already existing page of HTML and the success function uses the return to modify what's there. So the answer to "where do I get my formatting from" is that it's either already there, or the success function will create it by concatenating string literals and the returned data before injecting the results into the DOM.

It's not true that you "can't use HTML". You most certainly can, but you should adjust the $.ajax options accordingly. AJAX is seen as a way to offload presentation work to the client-side and JSON make great sense for the data format. But sometimes is just plain easier to send back HTML markup that's ready for display.

You can make $this->load->view('something') to return blocks of HTML to ajax.success. Read the docs again looking for the example on how to have view() return a string instead of outputting directly.
Reply


Messages In This Thread
HTML in Model - by AngelTrader - 09-25-2019, 11:13 PM
RE: HTML in Model - by ciadmin - 09-25-2019, 11:26 PM
RE: HTML in Model - by AngelTrader - 09-25-2019, 11:35 PM
RE: HTML in Model - by dave friend - 09-26-2019, 06:11 AM
RE: HTML in Model - by albertleao - 09-26-2019, 10:14 AM
RE: HTML in Model - by ciadmin - 09-26-2019, 10:30 AM
RE: HTML in Model - by AngelTrader - 09-26-2019, 10:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB