Jump to content


something i cant under stand

  • Please log in to reply
4 replies to this topic

#1 AviNahum

  • Members
  • PipPipPip
  • Advanced Member
  • 170 posts

Posted 04 July 2013 - 12:34 AM

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.

Visit my blog

#2 trq

  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 July 2013 - 01:06 AM

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?

#3 MironovDV

  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 12 July 2013 - 05:19 AM

Transmit raw data much faster

I'm from Russia. Sorry for my English!!!

#4 web_craftsman

  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts
  • LocationUkraine

Posted 12 July 2013 - 06:13 AM

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.

#5 blacknight

  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts
  • Locationsaint john

Posted 13 July 2013 - 01:55 AM

setting the datatype "dataType (default: Intelligent Guess (xml, json, script, or html))" you can return what you want from the call

if at first your fail google will give you a pass

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users