0

Why is better use an output json instead the normal html output in a call ajax? Wich are the reason for use it or in wich scenario is more useful use it?

user2864740
  • 60,010
  • 15
  • 145
  • 220
Fabrizio Fenoglio
  • 5,767
  • 14
  • 38
  • 75

1 Answers1

1

JSON is easily parsed by JavaScript and it is lightweigh.

Returning as JSON is generalization. i.e apart from your browser any other client which can process JSON can make use of response from the server. In this case your data and presentation are in separate layers.

Returning as HTML is specialization. Not all client can process the HTML response. In this case you are binding the data and presentation layer together.

There is a another thread that have discussed about this in details. Why is Everyone Choosing JSON Over XML for jQuery?

Community
  • 1
  • 1
shakthydoss
  • 2,551
  • 6
  • 27
  • 36