Ajax(以前是Ajax)和AJANE之间的实际区别是什么?

时间:2022-05-20 14:53:32

On February 18th, 2005, Jesse James Garrett gave the acronym AJAX (Asynchronous Javascript and XML) to an increasingly popular approach which harnessed the XMLHttpRequest object.

2005年2月18日,Jesse James Garrett将首字母缩略词AJAX(异步Javascript和XML)赋予了一种越来越流行的方法,该方法利用了XMLHttpRequest对象。

See: http://adaptivepath.org/ideas/ajax-new-approach-web-applications/

参见:http://adaptivepath.org/ideas/ajax-new-approach-web-applications/

Over a relatively short time JSON became the preferred data-interchange format and AJAX (now effectively AJAJ) became Ajax (a name - rather than an acronym - for one approach to asynchronous data retrieval).

在相对较短的时间内,JSON成为首选的数据交换格式,AJAX(现在实际上是AJAJ)变成了AJAX(一种异步数据检索方法的名称,而不是缩写)。

But what about AJANE (Asynchronous Javascript and Nothing Else)?

但是AJANE(异步Javascript)呢?

function retrieveMyAsynchronousData() {
    var myAsynchronousData = document.createElement('script');
    myAsynchronousData.setAttribute('src', '/data/my-asynchronous-data.js');
    document.body.appendChild(myAsynchronousData);
}

myElement.addEventListener('click', retrieveMyAsynchronousData, false);

It's beyond question that Ajax is the industry standard approach, not AJANE - but why? Is it faster, more secure, more optimised?

毫无疑问,Ajax是行业标准方法,而不是AJANE——但为什么呢?它是否更快、更安全、更优化?

  • What are the practical advantages of Ajax over AJANE?
  • 与AJANE相比,Ajax的实际优势是什么?
  • Why is the former a much more established approach than the latter?
  • 为什么前者比后者更成熟?
  • When developing, why should I use one approach over the other?
  • 在开发时,为什么我应该使用一种方法而不是另一种方法呢?

N.B. Please note, I am not asking for opinion or preference. I am trying to understand if there is an explicit, real-world, technical justification for deploying the XMLHttpRequest object over and above simply building a new <script> and adding it to the DOM.

注意,我不是在征求意见或偏好。我正在尝试理解是否存在一个显式的、真实的、技术上的理由来部署XMLHttpRequest对象,只需构建一个新的

1 个解决方案

#1


3  

AJANE (a term I've never heard of before today and which I can't find any reference to on Google) is more commonly known as JSONP. It:

AJANE(一个我以前从未听说过的术语,我在谷歌上找不到任何参考)通常被称为JSONP。它:

  • Requires the creation of a global variable to handle the response (well, that applies to normal JSONP. Your approach seems to involve the response including everything internally instead of being a simple function call that introduces the additional problems of:)
    • Multiple requests to the same endpoint have to fetch all the logic to handle it each time
    • 对同一端点的多个请求必须每次获取所有逻辑来处理它
    • The calling function is limited in what contextual information it can supply to globals and strings
    • 调用函数在它可以提供给全局和字符串的上下文信息中是有限的。
  • 需要创建一个全局变量来处理响应(这适用于普通的JSONP)。你的方法似乎涉及到反应包括内部,而不是一个简单的函数调用,它引入了额外的问题:)多个请求相同的端点必须获取所有的逻辑来处理它每次调用函数有限的上下文信息可以提供全局变量和字符串
  • Does not provide any information about the status of the response (e.g. you can't detect a 404 or 500 error)
  • 不提供任何关于响应状态的信息(例如,您无法检测到404或500错误)
  • Depends on injecting software into the page instead of data, which means you must absolutely trust the provider of the data
  • 依赖于将软件注入页面而不是数据,这意味着您必须绝对信任数据的提供者
  • Is limited to making GET requests
  • 是否仅限于发出请求

#1


3  

AJANE (a term I've never heard of before today and which I can't find any reference to on Google) is more commonly known as JSONP. It:

AJANE(一个我以前从未听说过的术语,我在谷歌上找不到任何参考)通常被称为JSONP。它:

  • Requires the creation of a global variable to handle the response (well, that applies to normal JSONP. Your approach seems to involve the response including everything internally instead of being a simple function call that introduces the additional problems of:)
    • Multiple requests to the same endpoint have to fetch all the logic to handle it each time
    • 对同一端点的多个请求必须每次获取所有逻辑来处理它
    • The calling function is limited in what contextual information it can supply to globals and strings
    • 调用函数在它可以提供给全局和字符串的上下文信息中是有限的。
  • 需要创建一个全局变量来处理响应(这适用于普通的JSONP)。你的方法似乎涉及到反应包括内部,而不是一个简单的函数调用,它引入了额外的问题:)多个请求相同的端点必须获取所有的逻辑来处理它每次调用函数有限的上下文信息可以提供全局变量和字符串
  • Does not provide any information about the status of the response (e.g. you can't detect a 404 or 500 error)
  • 不提供任何关于响应状态的信息(例如,您无法检测到404或500错误)
  • Depends on injecting software into the page instead of data, which means you must absolutely trust the provider of the data
  • 依赖于将软件注入页面而不是数据,这意味着您必须绝对信任数据的提供者
  • Is limited to making GET requests
  • 是否仅限于发出请求