Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax: Definition vs Implementation? (XML vs JSON vs Other)

AJAX actually means Asynchronous Javascript And XML. This term was derived because (as I know the story) the first people who started this process transferred data from the server to the client via XML. Lately (well ever since I've started using it actually), JSON has been around and appears to be a real alternative to XML. From my (possibly meager) tests and experience, JSON is smaller, easier, and better for transmitting data.

So my question is this: which do you use to talk to and from the server/client (and possibly why)? Or, what are the "best practices" that you have heard of (and why)?

Thanks all!

like image 701
Mike Avatar asked Dec 03 '22 08:12

Mike


1 Answers

We generally prefer xml because it has some advantages over JSON like:

  • Xml can be validated while json has no validator
  • No namespaces in json
  • Xml is extensible unlike json
  • Json is generally considered insecure

On the other hand json itself has its advantages:

  • Json is simpler
  • It's easier to process on the client side
  • Debugging can be a breeze when something goes wrong

In the end it depends on what you are trying to develop, for data-oriented stuff I prefer json.

like image 178
tHeSiD Avatar answered Dec 15 '22 07:12

tHeSiD