javascript 如何开始学习 Ajax?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3536609/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 01:26:05  来源:igfitidea点击:

How to start learning Ajax?

javascripthtmlajax

提问by Quentin

Ajax - Asynchronous JavaScript And XML

Ajax - 异步 JavaScript 和 XML

What does it include? HTML, JavaScript, XML, jQuery?

它包括什么?HTML、JavaScript、XML、jQuery?

What is the best way to start learning Ajax? Should I start from the basics of HTML and JavaScript or base my instruction on a particular language or library?

开始学习 Ajax 的最佳方法是什么?我应该从 HTML 和 JavaScript 的基础开始,还是应该根据特定语言或库来进行教学?

回答by Quentin

Ajax is, in short, the process of communicating with a webserver from a page, using JavaScript, without leaving the page.

简而言之,Ajax 是使用 JavaScript 从页面与 Web 服务器通信的过程,而无需离开页面。

The key things you need to know for this are:

为此,您需要了解的关键事项是:

  • The JavaScript needed to make the request and handle the response
  • The server side code needed to receive the request and make the response (unless you are using a service that provides this for you)
  • 发出请求和处理响应所需的 JavaScript
  • 接收请求并做出响应所需的服务器端代码(除非您使用的服务为您提供此服务)

The server side of this depends very much on what server side environment you are working with, so there is little useful that is specific that could be said. What can be usually said are what form the responses can take.

服务器端在很大程度上取决于您正在使用的服务器端环境,因此可以说的特定内容几乎没有用处。通常可以说的是回应可以采取什么形式。

  • JSONis a popular approach for sending structured data.
  • XML is another way to send structured data, but has been falling out of favour of late since JSON is, arguably, easier to work with.
  • Chunks of HTML are popular for shoving into pages with innerHTML.
  • Tiny bits of plain text are useful for simple responses.
  • JSON是一种流行的发送结构化数据的方法。
  • XML 是另一种发送结构化数据的方式,但最近已经失宠,因为 JSON 可以说更容易使用。
  • 大块的 HTML 很受欢迎,用于将innerHTML.
  • 少量纯文本对于简单的响应很有用。

As for the client side, there are three common approaches:

对于客户端,常见的有以下三种方式:

  • XMLHttpRequest: Well supported and flexible.
  • fetch: A replacement for XHR with a nicer API but more limited browser support.
  • JSONP: A hack to work around the Same Origin Policy rendered obsolete by the introduction of CORS but which you might stumble across from time to time.
  • XMLHttpRequest:支持良好且灵活。
  • fetch:用更好的 API 但更有限的浏览器支持来替代 XHR。
  • JSONP:一种解决同源策略的技巧,由于 CORS 的引入而变得过时,但您可能会不时偶然发现。

I mentioned the Same Origin Policy above. Normally a script isn't allowed to read data from another domainfor security reasons. The CORS standardallows you to work around this.

我在上面提到了同源策略。通常,出于安全原因,不允许脚本从另一个域读取数据。该CORS标准允许你解决这个问题。

Now for some resources:

现在获取一些资源:

回答by JWhiz

You Need to have knowledge of HTML and Javascript. W3Schoolshas a Tutorial on Basics which will help You learn. The best way to learn is to put some code and use it. And Moreover now, JQuery( a javascript library ) , makes learning Ajax more fun and easier. The Website has good documentation and some Sample Ajax code too.

您需要了解 HTML 和 Javascript。W3Schools有一个基础教程,可以帮助您学习。最好的学习方法是放一些代码并使用它。而且现在,JQuery(一个 javascript 库)使学习 Ajax 变得更加有趣和容易。该网站也有很好的文档和一些示例 Ajax 代码。

回答by Darin Dimitrov

AJAX = Asynchronous JavaScript and XML.

AJAX = 异步 JavaScript 和 XML。

So basically it is javascript. jQueryamong other things simplifies your code sending AJAX requests. HTML is markup, not language and is not related to AJAX.

所以基本上它是javascript。jQuery除其他外,还简化了发送 AJAX 请求的代码。HTML 是标记,不是语言,与 AJAX 无关。

You may start with this tutorial.

您可以从本教程开始。

回答by e2-e4

You need first to understand Javascript and how to program it. On my side, when I first started to develop Javascript, my experience was mainly C, C++, Perl and the like.

您首先需要了解 Javascript 以及如何对其进行编程。就我而言,刚开始开发Javascript时,我的经验主要是C、C++、Perl等。

Due to that background, it quickly occur to me the need in Javascript to be able to query data from the current page (without any redirection) to the web server dynamically. I then discovered the usual key Ajax object XMLHttpRequest.

由于这种背景,我很快意识到需要在 Javascript 中能够动态地从当前页面(无需任何重定向)查询数据到 Web 服务器。然后我发现了常用的关键 Ajax 对象 XMLHttpRequest。

I would recommend you to use the "regular" Javascript at first, perform some basic dynamic actions, like time display, moving text (...).

我建议您首先使用“常规”Javascript,执行一些基本的动态操作,例如时间显示、移动文本(...)。

Then you could try to implement a simple program that display the clock value from your server. Because XmlHttpRequest perform a dialog between the web server and the client (browser).

然后您可以尝试实现一个简单的程序来显示您的服务器的时钟值。因为 XmlHttpRequest 在 Web 服务器和客户端(浏览器)之间执行对话。

For that you need to have access to a web server (eg Apache). You need to chose what language you will use server side to answer the Xmlhttprequests, e.g. PHP, Perl CGI, etc... You need to have Apache dispatch the page requests to that PHP ... script. The script will have to output the result.

为此,您需要访问 Web 服务器(例如 Apache)。您需要选择您将使用服务器端的语言来回答 Xmlhttprequests,例如 PHP、Perl CGI 等...您需要让 Apache 将页面请求分派到该 PHP...脚本。脚本必须输出结果。

 Browser-Javascript request 

 ==> Web server (eg PHP) 
     to Display the clock =
                          "
 Back to browser        <==

The the javacript code will get that answer and will have to display that result somewhere.

javacript 代码将获得该答案,并且必须在某处显示该结果。

In terms of Book, Javascript 5 by Flanagan is my first choice.

就 Book 而言,Flanagan 的 Javascript 5 是我的首选。

回答by Ionu? Staicu

By actually using it. Is the best way of learning something. ANY thing!

通过实际使用它。是最好的学习方式。任何事物!