Building html structure in php or javascript?

Posted by Adam on Stack Overflow See other posts from Stack Overflow or by Adam
Published on 2012-09-22T21:34:59Z Indexed on 2012/09/22 21:37 UTC
Read the original article Hit count: 149

Filed under:
|

I've been doing a lot of ajax calls and using the returned data to build html with javascript. However, I've noticed some people are returning the constructed html in the ajax calls since they're doing it all in php.

What is the preferred method? I have a bunch of stuff already using javascript, so I guess I would prefer not changing everything to use just php. But, I'm assuming php would be more "secure."?

The following is what I've been doing:

$main_frag = $("<div class='order-container'/>");

$contact_frag = $("<div class='group'><div class='line-data'>Name: "+data.name+"</div><div class='line-data'>Email: "+data.email+"</div><div class='line-data'>Phone: "+data.phone+"</div></div>");

$address_frag = $("<div class='group'><div class='line-data'>Address 1: "+data.address_one+"</div><div class='line-data'>Address 2: "+address2+"</div><div class='line-data'>City: "+data.city+"</div><div class='line-data'>Province: "+data.province+"</div><div class='line-data'>Postal Code: "+data.postal+"</div></div>");

etc..

I just want to hear the opinions of the community.

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript