AviNahum Posted July 4, 2013 Share Posted July 4, 2013 hey there, lately im was working on a new application that required alot of ajax requests... i was wondering, many websites return fom the server a json object and then creates the html elements with javasript and then appending it to the document. why not return the html from the server and then just append it to a div, which is more easier! for example, lets say i want to print a table with shop items and their prices, why should i return a json object and then print a table with javascript with the data insted of return the whole html table from the server? am i missing something? thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/279847-something-i-cant-under-stand/ Share on other sites More sharing options...
trq Posted July 4, 2013 Share Posted July 4, 2013 One advantage is that returning raw data as json allows your data to be consumed by other types of clients. This is how API's work. Another, is that your not mixing your client side concerns with your server side concerns. Why should your server side code need to create table rows and divs? Quote Link to comment https://forums.phpfreaks.com/topic/279847-something-i-cant-under-stand/#findComment-1439366 Share on other sites More sharing options...
MironovDV Posted July 12, 2013 Share Posted July 12, 2013 Transmit raw data much faster Quote Link to comment https://forums.phpfreaks.com/topic/279847-something-i-cant-under-stand/#findComment-1440425 Share on other sites More sharing options...
web_craftsman Posted July 12, 2013 Share Posted July 12, 2013 One time I met a situation when I needed to load a big amount of data from server via ajax (first loading data for ajax application). And then a needed to create my page from that data. All my researches showed me that it worked faster when I received a formed html from the server. In spite of bigger traffic. Browsers are not very fast workers when you need to form some big DOM structures on the fly. Quote Link to comment https://forums.phpfreaks.com/topic/279847-something-i-cant-under-stand/#findComment-1440427 Share on other sites More sharing options...
blacknight Posted July 13, 2013 Share Posted July 13, 2013 setting the datatype "dataType (default: Intelligent Guess (xml, json, script, or html))" you can return what you want from the call Quote Link to comment https://forums.phpfreaks.com/topic/279847-something-i-cant-under-stand/#findComment-1440550 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.