Ajax: Definition versus implementation? (XML vs JSON vs Other)

AJAX actually means asynchronous Javascript and XML. This term was obtained because (as I know the story) the first people who started this process transferred data from the server to the client using XML. Lately (well since I actually started using it), JSON exists and seems like a real alternative to XML. Of my (possibly meager) tests and experience, JSON is less, easier, and better for data transfer.

So my question is: what do you use to communicate with the server / client (and maybe why)? Or what “best practices” have you heard (and why)?

Thanks everyone!

+4
source share
10 answers

JSON over XML seems to continue the discussion - I would rather go with JSON, as it is better suited for web services that feed mashup and AJAX widgets, because these are essentially serialized Javascript objects (and therefore they are easy to use with Javascript).

You can find a significant comparison of the advantages and disadvantages of JSON and XML with JSON or XML, which format to choose? and AJAX Answer: XML, HTML or JSON?

+3
source

Usually we prefer xml because it has some advantages over JSON:

  • Xml can be verified and json has no validator
  • No namespace in json
  • Xml extends unlike json
  • Json is generally considered unsafe

On the other hand, json itself has its advantages:

  • Json is easier
  • Easier to handle on the client side.
  • Debugging can be easy when something goes wrong.

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

+5
source

Which one is better to use is a specific application / requirement. On the browser side, JSON is the best choice, while on the server side, it is better to use XML for files. Use the right tool for the right job. JSON is more about data, and XML is more about document. JSON is supported based on JavaScript Javascript code.

For more information about this post, refer to the link, which has a more pleasant comparison of each with examples. http://codebucket.co.in/which-one-is-better-xml-or-json/

+5
source

I prefer to use JSON whenever possible:

  • It already appeared as a Javascript object, so you need to make an eval () call on it to capture all its data.
  • JSON is Javascript, so it runs faster for people who already know JS but don’t have the intricacies of XML.
  • In a browser, you don’t need to experience pain when parsing an XML object. (You also don't need to create one on the server, although you still need to create JSON.)
  • This is a more compact way to transfer data.
+2
source

These days I gravitate to JSON. It certainly feels lighter and more “natural” in combination with client-side coding.

Best security practice: never blindly change JSON without checking the resulting string, since you can execute arbitrary code that someone puts in the JSON string.

Douglas Crockford has written a good set of security principles for working with JSON.

+1
source

I always smile when I see the term AJAX. I smile because I first started using the same method long before even XMLHTTP existed, not to mention AJAX.

We did the same as AJAX in an Intranet application in IE, but using VBScript and a Java applet instead of XMLHTTP. We used something similar to JSON, but in VBScript syntax.

+1
source

In theory, XML will be quickly good because of validation and what not. In practice, you cannot test the client side against a DTD or schema (or in most cases at all). Try it, you will see.

XML also suffers from verbosity and client-side consumption. If you do not plan to use XSLT or something else and directly consume the resulting package, you need to slice the data using the DOM, as done.

Finally, XML cannot be sensible until it is complete (at least on the client side), so you cannot perform partial validation. Although, to be fair, JSON will also have problems there, depending on how it is structured.

Given the consumption environment (mostly JavaScript), JSON has an obvious leg. There is a massive discussion of this choice, as well as other things like YAML data, CSV, base64, HTML snippets, etc. In chapter 4, Ajax: a complete reference ( http://ajaxref.com ), which is only on data types. Examples confirm ease of handling, especially in less well-known cases. If I were to select one JSON, it would be frank for some applications of small HTML fragments of Ajax (since it is slap and go) - a way to do this.

+1
source

You can also just generate html and use this output directly in your application. XML is very verbose, where JSON requires extra attention when processing it due to security.

Actually there is no "best practice." Personally, if I chose JSON and XML, I would use JSON. Although you have some interesting query features if you use XML.

0
source

I think the debate over JSON and XML shows that JSON may be the best practice. I do not think that client-server data transfer rates will soon disappear as a problem, if ever. Therefore, I think JSON will win the issue of being smaller alone (I believe JSON also has the flexibility of which server it can be sent to, but this is naturally related to security issues, as mentioned )

Maybe we should start calling it "AJAWX" (asynchronous JAvascript without Xml).

0
source

My choice is JSON.

Because:

  • it is much faster. You just need to evaluate the JSON code from the response instead of XML parsing.
  • it requires much less code. eval () is less than XML parser code.
  • less traffic (amount of data to transfer) between client and server as a result of faster processing
  • it is more readable
0
source

All Articles