I am about to write codes for presenting information, in some cases, I will get outputs as a list with a pager. I need your help about deciding between two:
- Passing values to client side with AJAX in JSON format and modifying HTML with DOM, maybe creating a hidden div and table somewhere and creating an instance of it, filling with values and inserting somewhere with innerHTML function. I have never tried this one, so please tell me about the drawbacks of this. This will make my View Class in javascript when leaving Model And Controller Class in PHP.
- Returning an HTML table with an AJAX request and inserting on page
with innerHTML function (This seems to be the classical, safe
solution)
- What are the drawbacks of handling formatting and view related
operations in javascript? - Is formatting in javascript easy?
- Will I be able to edit a template table for displaying values with
javascript? - SHould I create a div somewhere or should I build a table with
string values in javascript? - Do I have to use Innerhtml each time?
- Is it easy to build an html output using javascript code like we do
in PHP? (like echo -table -tr -td -data)
for the people who automaticly ask for code, I am adding some, knowing that it is not actually necessary.
var ccomment= {
commentmin:10,
commentmax:1000,
view:function(commentid){}, //I am planning to present data with this
viewbyopinionid:function(opinionid){},
viewbyactorid:function(actorid){},
insert:function(opinionid,comment){},
remove:function(commentid){}
}
I use PHP and JQuery; I am writing Object Oriented code in both.
Php has a function json_encode which will convert an array to a json compatible string. I’d use that and set the return data type to json.