First, sorry for my English, you can correct me in that area too :)
I know that i can replace text in html with <?=$var?>
for example. Also, i can do it through ajax. I use $.ajax to get data in JSON format, than inside jquery i'm changing appearance of my web app.
This is example of getting data, and inside this function i'm calling $.View function where apperance is changing.
$.Model = function(route, data){
$.ajax({
url: "php/books.php?"+route,
type: "POST",
data: {data: data}
}).done(function(response){
var resp = JSON.parse(response);
$.View(route, resp, data);
}).fail(function(msg){
console.log('something is wrong');
});
});
};
Example of $.View function
$.View = function(route, response, data){
if(route==='menuItem'){
var studio='';
$.each(response, function(index, value){
studio += '<button id='+value['STUDIJI_ID']+' class="btn btn-primary studio_button">'+value['STUDIO']+'</button>';
});
$(studio).appendTo(".here");
}
};
So, my question is, what is the best approach for such things? Embed PHP variable to html or do it through jQuery on described way? Or, something third?
Thank you for your time and help.