Jump to content


Photo

something i cant under stand


  • Please log in to reply
4 replies to this topic

#1 AviNahum

AviNahum

    Advanced Member

  • Members
  • PipPipPip
  • 169 posts

Posted 03 July 2013 - 07:34 PM

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

trq

    Advanced Member

  • Administrators
  • 30,731 posts
  • LocationSydney, Australia.

Posted 03 July 2013 - 08:06 PM

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?

http://thorpesystems.com | http://proemframework.org | http://github.com/trq

SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
OPM - My Linux package manager.


#3 MironovDV

MironovDV

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 12 July 2013 - 12:19 AM

Transmit raw data much faster


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


#4 web_craftsman

web_craftsman

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts
  • LocationUkraine

Posted 12 July 2013 - 01: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

blacknight

    Advanced Member

  • Members
  • PipPipPip
  • 238 posts
  • Locationsaint john

Posted 12 July 2013 - 08:55 PM

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

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com