I was wondering if what I'm doing is fine, it works but I've this obsession to find a possible better way to do it. Basically I've to serve a user profile in a "Modal-box". So a user clicks on a button/link and this window is dynamically generated and its content-div is populated with the result of an AJAX request. Actually the AJAX request calls a php script that get the data from a MySQL database, get an HTML template through the php output-buffer and it stores that file as a string in a variable, then this variable is stored in an array, json-encoded and echoed out as something like that:
[ { success: 1, html: "HTML already formatted with data from the PHP script" } ]
On the client side, when my AJAX call is done I just fill my modal-content div with the html, so it is something like that:
.done( function ( srv-data ) {
if ( srv-data.success === 1 ){
$( "#modal-content" ).html( srv-data.html );
}
});
Is this a reasonable way to serve my HTML to the front-end? Or there are better ways to do something similar? I use this solution just for that case where I've a lot of HTML to render with a lot of fields in the database to work with, other AJAX responses are just looped through the Object and rendered on the client side.
Thanks for your time.