What is the difference between JSON and AJAX with jQuery?

前端 未结 4 1379
忘了有多久
忘了有多久 2021-01-31 06:04

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 i

4条回答
  •  我在风中等你
    2021-01-31 06:23

    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.

提交回复
热议问题