在学习 Ajax 之前我需要了解什么? [英] What do I need to know before learning Ajax?

查看:38
本文介绍了在学习 Ajax 之前我需要了解什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ajax - 异步 JavaScript 和 XML

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

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

解决方案

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

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

  • 发出请求和处理响应所需的 JavaScript
  • 接收请求和做出响应所需的服务器端代码(除非您使用的服务为您提供此服务)

服务器端在很大程度上取决于您所使用的服务器端环境,因此几乎没有什么具体可用的说法.通常可以说的是回应可以采取什么形式.

  • JSON 是一种流行的发送方式结构化数据.
  • XML 是另一种发送结构化数据的方式,但由于 JSON 可以说更易于使用,因此最近逐渐失宠.
  • 将 HTML 块放入带有 innerHTML 的页面中很受欢迎.
  • 少量纯文本对于简单的响应很有用.

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

  • XMLHttpRequest:支持良好且灵活.
  • fetch:XHR 的替代品,具有更好的 API,但浏览器支持更有限.
  • JSONP:一种解决同源策略的方法,由于 CORS 的引入而过时,但您可能会不时发现它.

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

现在提供一些资源:

Ajax - Asynchronous JavaScript And XML

What does it include? 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 is, in short, the process of communicating with a webserver from a page, using JavaScript, without leaving the page.

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)

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.

  • JSON is 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.

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.

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

Now for some resources:

这篇关于在学习 Ajax 之前我需要了解什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆