Should I use JSON or AJAX for response data?

Why json Today I did some tests, and the request time for JSON or regular AJAX request was the same. In the “normal request” I returned the full text + html tags in the JSON request, logically I returned the “json return type” and I created the HTML code with client JavaScript.

I don’t understand why large sites (Google Reader, etc.) or even small sites use JSON? Or do I not understand when should I use JSON?

+7
json javascript jquery xml ajax
source share
2 answers

You may be a little confused.

JSON and AJAX are not any choice.

JSON and XML are choices.

JSON and AJAX are different and largely unrelated, although AJAX often uses JSON, it can just use XML, HTML, or plain text.

Or do you mean X in AJAX (XML)? If so, the arguments for JSON are basically:

  • JSON has less payload than the XML equivalent; and
  • JSON is easier to handle in Javascript (compare eval'ing a JSON object with the progress of an XML fragment).

Other than that, it is largely a personal preference.

+41
source share

JSON is just a data exchange format. It describes how data is presented during transmission. You cannot replace Ajax with JSON.

Ajax means asynchronous JavaScript and XML, but when using JSON you can say that you are using AJAJ (asynchronous JavaScript and JSON).

Perhaps you are thinking of the jQuery methods $.getJSON() and $.get() ?

The difference is that $.getJSON() automatically assumes that the JSON data, and $.get() will simply retrieve the data in plain text.

When using $.getJSON() you can also retrieve data between domains.

+13
source share

All Articles