本文介绍了JSON和AJAX与jQuery之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说JSON序列化所有的数据,这阻止了我在客户端在跨浏览器支持等问题。

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

我已经使用AJAX与jQuery和它似乎很容易,但我不确定的差异,

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
});

任何人都可以解释使用JSON创建jQuery AJAX请求和创建jQuery AJAX请求而不使用json类型?

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?

推荐答案

AJAX代表 A 同步 J 抗性 nd X ML,这是一种用于使用JavaScript启动异步HTTP请求到服务器的机制。不要让这个名字愚弄你;您没有限制只从这种技术检索JavaScript或XML。您可以很高兴地返回其他数据格式(HTML,纯文本和JSON,以列出几个)。

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只是其中一种格式。这是一种数据交换格式,因为AJAX是在启动页面加载完成后与服务器通信的技术。

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.

要回答您是否需要指定 dataType 的问题; jQuery最好猜测响应格式(无论是HTML还是JSON等),所以通常可以省略它。

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.

这篇关于JSON和AJAX与jQuery之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 20:33
查看更多