带有 JavaScript 的 AJAX 和 jQuery 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3127938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between AJAX with JavaScript and jQuery?
提问by Jay
What is the difference between AJAX with jQuery and AJAX with JavaScript?
jQuery 的 AJAX 和 JavaScript 的 AJAX 有什么区别?
采纳答案by Tyler
Javascript, for the purposes of this question, is a client-side (in the browser) scripting language.
就这个问题而言,Javascript 是一种客户端(在浏览器中)脚本语言。
jQuery is a library/framework built with Javascript. It is very popular because it (nearly universally) abstracts away cross-browser compatibility issues and it emphasises unobtrusive and callback-driven Javascript programming.
jQuery 是一个用 Javascript 构建的库/框架。它非常受欢迎,因为它(几乎普遍地)抽象了跨浏览器兼容性问题,并强调了不引人注目和回调驱动的 Javascript 编程。
AJAX (Asynchronous Javascript XML) is a method to dynamically update parts of the UI without having to reload the page - to make the experience more similar to a desktop application.
AJAX(异步 Javascript XML)是一种无需重新加载页面即可动态更新 UI 部分的方法 - 使体验更类似于桌面应用程序。
EDIT:
编辑:
It sounds like you're new to this. I would seriously recommend you check out http://www.w3schools.com/js/default.aspto get started. It's what I used to learn javascript and it's done incredibly well.
听起来你是新手。我强烈建议您查看http://www.w3schools.com/js/default.asp以开始使用。这就是我用来学习 javascript 的内容,而且做得非常好。
回答by gblazex
Actually only one of them is a programming language.
实际上,其中只有一种是编程语言。
Javascriptis a programming languagewhich is used mainly in webpages for making websites interactive. In this context, when a webpage is parsed by the browser, it creates an in-memory representation of the page. It is a tree structure, which contains all elements on the page. So there is a root element, which contains the head and the body elements, which contain other elements, which contain other elements. So it looks like a tree basically. Now with javascript you can manipulate elements in the page using this tree. You can pick elements by their id (getElementsById), or their tag name (getElementsByTagName), or by simply going through the tree (parentNode, firstChild, lastChild, nextSibling, previousSibling, etc.). Once you have element(s) to work with you can modify them by changing their look, content or position on the page. This interface is also known as the DOM (Document Object Model). So you can do everything with Javascript that another programming language can do, and by using it embedded into wepages you also get an in-memory Object of the current webpage by which you can make changes to the page interactively.
In recent years JavaScripthas also become a popular server-sidelanguage running in an environment called Node.js. This opened up a way for you to share common parts of your code between the browser and the server.
AJAXis a technique of communicationbetween the browser and the server within a page. Chat is a good example. You can write a message, send a message and recive other messages without leaving the page. You can manage this network interaction with Javascript on the client side, using an XMLHTTP Objectprovided by the browser.
jQueryis a library which aims to simplifyclient side web development in general (the other two above). It creates a layer of abstracion so you can reuse common languages like CSS and HTML in Javascript. It also includes functions which can be used to communicate with servers very easily (AJAX). It is written in Javascript, and will not do everything for you, only makes common tasks easier. It also hides some of the misconceptions and bugs of browsers.
Javascript是一种编程语言,主要用于网页中以使网站具有交互性。在这种情况下,当浏览器解析网页时,它会创建页面的内存表示。它是一个树状结构,包含页面上的所有元素。所以有一个根元素,它包含 head 和 body 元素,其中包含其他元素,其中包含其他元素。所以它基本上看起来像一棵树。现在使用 javascript,您可以使用此树操作页面中的元素。您可以通过它们的 id (getElementsById) 或它们的标记名称 (getElementsByTagName) 或简单地遍历树来选择元素(parentNode、firstChild、lastChild、nextSibling、 previousSibling 等)。一旦有了要使用的元素,您就可以通过更改它们在页面上的外观、内容或位置来修改它们。此接口也称为DOM(文档对象模型)。因此,您可以使用 Javascript 执行其他编程语言可以执行的所有操作,并且通过将其嵌入到网页中,您还可以获得当前网页的内存对象,您可以通过该对象以交互方式更改页面。
近年来,JavaScript也成为运行在Node.js环境中的流行服务器端语言。这为您在浏览器和服务器之间共享代码的公共部分开辟了道路。
AJAX是一种页面内浏览器和服务器之间的通信技术。聊天就是一个很好的例子。您可以在不离开页面的情况下编写消息、发送消息和接收其他消息。您可以使用浏览器提供的XMLHTTP 对象在客户端通过 Javascript 管理此网络交互。
jQuery是一个旨在简化客户端 Web 开发的库(上面的其他两个)。它创建了一个抽象层,因此您可以在 Javascript 中重用常见的语言,如 CSS 和 HTML。它还包括可用于非常轻松地与服务器通信 (AJAX) 的功能。它是用 Javascript 编写的,不会为你做所有的事情,只会让常见的任务更容易。它还隐藏了浏览器的一些误解和错误。
To sum up:
总结:
- Javascript is a programming language (objects, array, numbers, strings, calculations)
- AJAX and jQuery uses Javascript
- jQuery is for simplifing common tasks with AJAX and page manipulation (style, animation, etc.)
- Javascript 是一种编程语言(对象、数组、数字、字符串、计算)
- AJAX 和 jQuery 使用 Javascript
- jQuery 用于通过 AJAX 和页面操作(样式、动画等)简化常见任务
Finally, an example just to see some syntax:
最后,举个例子只是为了看看一些语法:
// page manipulation in javascript
var el = document.getElementById("box");
el.style.backgroundColor = "#000";
var new_el = document.createElement("div");
el.innerHTML = "<p>some content</p>";
el.appendChild(new_el);
// and how you would do it in jQuery
$("#box")
.css({ "background-color": "#000" })
.append("<div><p>some content</p></div>");
回答by Darin Dimitrov
Of the three only javascript is a programming language. jQueryis a framework that is based on javascript and that simplifies some tedious tasks like manipulating the DOM, adding some effects and animations and most importantly doing it in a cross browser fashion. One of the tasks that is simplified by jQuery is AJAXwhich is a concept allowing a browser to send an asynchronous request to a web server allowing for richer web applications.
在这三个中,只有 javascript 是一种编程语言。jQuery是一个基于 javascript 的框架,它简化了一些繁琐的任务,例如操作 DOM、添加一些效果和动画,最重要的是以跨浏览器的方式进行。jQuery 简化的任务之一是AJAX,它是一个概念,允许浏览器向 Web 服务器发送异步请求,从而支持更丰富的 Web 应用程序。
回答by Junaid
AJAX is technology.Jquery is library. Javascript is language.
AJAX 是技术。Jquery 是库。Javascript 是语言。
回答by Srikar Doddi
AJAX is a method to do an XMLHttpRequest from a web page to the server and send/retrieve data to be used on the web page. It stands for Asynchronous Javascript And XML. It uses javascript to construct an XMLHttpRequest(varies between browsers).
AJAX 是一种从网页到服务器执行 XMLHttpRequest 并发送/检索要在网页上使用的数据的方法。它代表异步 Javascript 和 XML。它使用 javascript 来构造一个 XMLHttpRequest(因浏览器而异)。
jQuery is a javascript framework that can be used to manipulate the DOM (search and interact with the DOM). jQuery implements a high-level interface to do AJAX requests abstractly thereby giving multi-browser support in making the request.
jQuery 是一个 javascript 框架,可用于操作 DOM(搜索并与 DOM 交互)。jQuery 实现了一个高级接口来抽象地执行 AJAX 请求,从而在发出请求时提供多浏览器支持。
So, Ajax is a technology paradigm, whereas jquery is a library so can't compare them.
因此,Ajax 是一种技术范式,而 jquery 是一个库,因此无法比较它们。
回答by Void
AJAX is a way to talk to the server in the background. JavaScript is a language that the browser understands. jQuery is a JavaScript framework that makes life easier for people who want to program for the browser.
AJAX 是一种在后台与服务器对话的方式。JavaScript 是一种浏览器可以理解的语言。jQuery 是一个 JavaScript 框架,它使想要为浏览器编程的人的生活更轻松。
回答by ArCiGo
JS is a client-side programming language.
jQuery is a framework, but isn't the only one. Another JS frameworks are AngularJS, Mootools, NodeJS, BackboneJS, etcetera. With anyone of this frameworks you will do any action that pure JS can't do, or any "complex" (I don't find the correct word) action. As Void said, adapting his answer to my answer about frameworks: "makes life easier for people who want to program for the browser."
With AJAX you can communicate your Web page to the server. AJAX depends on JS to work.
JS 是一种客户端编程语言。
jQuery 是一个框架,但不是唯一的。另一个 JS 框架是 AngularJS、Mootools、NodeJS、BackboneJS 等。使用此框架中的任何一个,您将执行纯 JS 无法执行的任何操作,或任何“复杂”(我找不到正确的词)操作。正如 Void 所说,将他的回答改编为我关于框架的回答:“让想要为浏览器编程的人的生活更轻松。”
使用 AJAX,您可以将您的网页传送到服务器。AJAX 依赖 JS 来工作。
回答by Danesh
Javascript is a scripting language, Not a programing language. Jquery and ajax are simplified version of javascript which helps manupulate queries of certain part of website without having to change the entire user interface of the website.
Javascript 是一种脚本语言,而不是一种编程语言。Jquery 和 ajax 是 javascript 的简化版本,可帮助处理网站特定部分的查询,而无需更改网站的整个用户界面。

