javascript - which one is faster when render HTML -
php return json, javascript createelement add data.
type: 'post', data: "do=view&start=0&stop=100", success:function(data){ var parsedjson = $.parsejson(data); var jexcel = document.getelementbyid('jexcel'); for(var i=0; i<parsedjson.id.length; i++) { var cell1 = document.createelement("input"); var cell2 = document.createelement("input"); cell1.setattribute("type", "text"); cell1.setattribute("value", parsedjson.id[i]); cell2.setattribute("type", "text"); cell2.setattribute("value", parsedjson.username[i]); jexcel.appendchild(cell1); jexcel.appendchild(cell2); jexcel.innerhtml += "<br>"; } }php return
echo "<input type~~">
i don't think find answer 100% correct 100% of time.
it comes down speed of downloading html result vs speed of java script dom manipulation , vary depending on variables involved in output, , how data produced etc.
in case though, bet money number 2 fastest case 9 times out of 10, downloading php response faster dom manipulation on client side.
go method 2 unless have time , know-how accurately time these 2 methods.
i have honest, have never seen consider method 1 , interested in knowing why have?
Comments
Post a Comment