Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between JSON and AJAX with jQuery?

I've heard that JSON serializes all the data, which stops me having problems client side in terms of cross-browser support etc..

I've been using AJAX with jQuery and it seems easy, but I'm unsure of the differences,

I've read I can also use this to get the data:

$.ajax({
  url: url,
  dataType: 'json',
  data: data,
  success: callback
});

Can anyone explain the difference between making a jQuery AJAX request using JSON and making a jQuery AJAX request without the json type?

Will the answer be ok for all browsers?

like image 439
jpganz18 Avatar asked Feb 22 '12 15:02

jpganz18


People also ask

What is the difference between jQuery and AJAX?

AJAX is a web development technique for making asynchronous calls to the server. jQuery is a JavaScript library for designing and make some web development tasks easy. It makes it possible to run javascript outside of the browser. It works on the browser or outside the browser also.

What is jQuery AJAX JSON?

jQuery provides several methods for AJAX functionality. With the jQuery AJAX methods, you can request text, HTML, XML, or JSON from a remote server using both HTTP Get and HTTP Post - And you can load the external data directly into the selected HTML elements of your web page!

What is the use of AJAX and JSON?

According to the AJAX model, web applications can send and retrieve data from a server asynchronously without interfering with the display and the behavior of the existing page. Many developers use JSON to pass AJAX updates between the client and the server.

What is the difference between JSON and AJAX?

JSON (JavaScript Object Notation) and AJAX (Asynchronous JavaScript and XML) are two completely different concepts, one is used as a storage medium for data (JSON) while the other is used to retrieve data from a HTTP or FTP web server (AJAX) which is not dependent on the format of the data to be transferred, it can be ...


1 Answers

I think you are confusing the terms.

AJAX stands for Asynchronous Javascript and XML, which is a mechanism used to launch asynchronous HTTP requests to a server using JavaScript. Don't let the name fool you; there's no restriction on you only retrieving JavaScript or XML from this technique. You can quite happily return other data formats as well (HTML, plain text and JSON, to list a few).

JSON is just one of these formats. It's a data interchange format, where-as AJAX is a technique to communicate with a server after the initate page load has completed.

To answer your question on whether you need to specify the dataType; jQuery will best guess the response format (be it HTML or JSON etc), so you're usually fine to omit it.

like image 88
Matt Avatar answered Oct 25 '22 14:10

Matt