Jump to content

something i cant under stand


AviNahum

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.