Home > Web Front-end > JS Tutorial > body text

Ajax asynchronous request technology examples explained

亚连
Release: 2018-05-22 10:23:24
Original
2425 people have browsed it

ajax is a technology that can update parts of a web page without reloading the entire web page. Let me share with you an example of Ajax asynchronous request technology through this article. It is very good and has reference value. Friends who need it can refer to it

The full name of AJAX is Asynchronous JavaScript and XML (asynchronous JavaScript and XML).

AJAX is not a new programming language, but a new way of using existing standards. ajax is the art of exchanging data with the server and updating parts of a web page without reloading the entire page.

ajax is a technology that can update parts of a web page without reloading the entire web page.

ajax is a technology used to create fast dynamic web pages. By exchanging small amounts of data with the server in the background. Ajax allows web pages to be updated asynchronously. This means that parts of a web page can be updated without reloading the entire page. If traditional web pages (which do not use ajax) need to update content, the entire web page must be reloaded.

In the process of web application development, the industry seems to have no clear concept of the dividing line between the front and back ends, but most people use the browser as the dividing line between the front and back ends. The part of the browser that displays pages for users is called the front end, and all the code that runs on the server and provides business logic and data preparation for the front end is collectively called the back end.

Although the separation of front-end and back-end has begun to attract attention a few years ago, many people have only heard its sound but not seen its form, so they are not interested in it. There are some misunderstandings, and they mistakenly believe that the separation of front-end and back-end is just a development model of Web applications. As long as the front-end and front-end development work is divided during the development period of the Web application, it is the separation of front-end and back-end.

In fact, this is not the case. To be precise, the separation of front-end and back-end is not just a development model, but an architectural model of Web applications. During the development period, front-end and back-end engineers can implement parallel development by agreeing on interactive interfaces; during the run-time, the front-end and back-end separation mode requires separate deployment of web applications, and the front-end and back-end use HTTP requests to interact.

1. JSON parsing

JSON (JavaScript Object Notation) is a lightweight Data exchange format. JSON uses a completely language-independent text format. These characteristics make JSON an ideal data exchange language. Easy for humans to read and write, and easy for machines to parse and generate. Simply put, JSON converts a set of data represented in a JavaScript object into a string, which can then be easily passed between functions, or from a web client to a server in an asynchronous application terminal program.

2. Ajax interface call

Separation of front-end and back-end means that JSON is used to communicate between the front-end and the two development teams. Use the API to interact as a contract, via JSON strings, and then pass the strings from the web client to the server-side program in an asynchronous application. What you learn in this part is how to initiate an Ajax request from the front desk to the background, and finally update the front-end page after getting the data response returned by the server.

3. PHP backend

PHP is a popular general-purpose Scripting language, especially suitable for web development. The PHP language has the following characteristics:

1. Cross-platform, superior performance, and very economical when combined with many free platforms, such as LAMP (Linux /Apache/Mysql/PHP) or FAMP (FreeBSD/Apache/Mysql/ PHP), or if the data application is large enough, you can consider changing to PostgreSQL or Oracle, which supports N types of databases. (N >= 10)

2. The syntax is simple, if you have learned C and Perl, it is easy to get started, and it is partially similar to ASP. There are mature development tools, such as NuPHPed, or Zend Studio, etc., and you can use Eclipse and so on under the Linux platform.

3. Currently, mainstream technologies are supported, such as WebService, Ajax, XML, etc., which are sufficient for application.

4. There are many mature frameworks, such as the framework that supports MVC: phpMVC, the framework that supports event-driven events like ASP.net: Prado, the framework that supports rapid development like Ruby On Rails: Cake, etc. Sufficient for your application needs.

5. PHP 5 already has a mature object-oriented system that can adapt to basic object-oriented requirements. Suitable for developing large-scale projects.

This part mainly learns how to build a PHP server, master the basic syntax of PHP, generate a dynamic web page through PHP, master how to use PHP to complete a standardized interface, and finally return JSON data to the front desk.

四、数据库

数据库(Database)是按照数据结构来组织、存储和管理数据的仓库,每个数据库都有一个或多个不同的API用于创建,访问,管理,搜索和复制 所保存的数据。我们也可以将数据存储在文件中,但是在文件中读写数据速度相对较慢。

MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司。MySQL是一种关联数据库管理系统,关联数据库将数据保存在 不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。

• Mysql是开源的,所以你不需要支付额外的费用。

• Mysql支持大型的数据库。可以处理拥有上千万条记录的大型数据库。

• MySQL使用标准的SQL数据语言形式。

• Mysql可以允许于多个系统上,并且支持多种语言。这些编程语言包括C、C++、Python、Java、Perl、PHP、Eiffel、Ruby和Tcl等。

• Mysql对PHP有很好的支持,PHP是目前最流行的Web开发语言。

• MySQL支持大型数据库,支持5000万条记录的数据仓库,32位系统表文件最大可支持4GB,64位系统支持最大的表文件为8TB。

这部分主要学习的是数据中的增删改查操作,最后通过php访问数据中的数据,然后通过响应的处理,发挥给前台使用。

五、Ajax跨域

由于在工作中需要使用AJAX请求其他域名下的请求,但是会出现拒绝访问的情况,这是因为基于安全的考虑,AJAX只能访问本地的资源,而不能跨域访问。

解决方式一:

“XHR2” 全称 “XMLHttpRequest Level2” 是HTML5提供的方法,对跨域访问提供了很好的支持,并且还有一些新的功能。

* IE10以下的版本都不支持

* 只需要在服务器端头部加上下面两句代码:

header( "Access-Control-Allow-Origin:*" );
header( "Access-Control-Allow-Methods:POST,GET" );
Copy after login

解决方式二:

JSONP(JSON with Padding)是一个非官方的协议,它允许在服务器端集成Script tags返回至客户端,通过javascript callback的形式实现跨域访问(这仅仅是JSONP简单的实现形式)。

由于同源策略的限制,XmlHttpRequest只允许请求当前源(域名、协议、端口)的资源,为了实现跨域请求,可以通过script标签实现跨域请求,然后在服务端输出JSON数据并执行回调函数,从而解决了跨域的数据请求。

上面是我整理给大家的,希望今后会对大家有帮助。

相关文章:

jQuery Validator验证Ajax提交表单的方法和Ajax传参的方法(图文教程)

Ajax跨域请求的原理(图文教程)

Ajax 配合node js multer 实现文件上传功能

The above is the detailed content of Ajax asynchronous request technology examples explained. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!