Examples of Ajax asynchronous requests and ajax asynchronous requests

Source: Internet
Author: User
Tags php server

Examples of Ajax asynchronous requests and ajax asynchronous requests

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

AJAX is not a new programming language, but a new method that uses existing standards. Ajax is the art of exchanging data with the server and updating some webpages without reloading the entire page.

Ajax is a technology that updates some webpages without the need to reload the entire webpage.

Ajax is a technology used to create fast dynamic web pages. Exchange a small amount of data with the server in the background. Ajax enables asynchronous update of web pages. This means that you can update a part of a webpage without reloading the entire webpage. For traditional web pages (without ajax), if you need to update the content, you must reload the entire web page.

In the Web application development process, the industry does not seem to have a definite concept of the front-end line, but most people use browsers as the front-end line. The front-end part of the page displayed for users in the browser is called the front-end, and all the code that runs on the server and provides the business logic and data for the front-end is collectively referred to as the back-end.

Although the frontend and backend separation has been concerned for a few years ago, many people only hear its voice and do not see it, so there are some misunderstandings about it, it is mistaken that the frontend and backend separation is only a Web application development mode. As long as the frontend and backend development work is carried out during the Web application development period, the division of labor is the frontend and backend separation.

This is not the case. To be accurate, frontend and backend separation is not just a development mode, but an architecture mode of Web applications. During the development period, frontend and backend engineers can achieve parallel development by setting up interactive interfaces. During the runtime, The frontend and backend separation modes need to separate and deploy Web applications, the frontend and backend use HTTP requests for interaction.

I. JSON Parsing

JSON (JavaScript Object Notation) is a lightweight data exchange format. JSON uses a language-independent text format. These features make JSON an ideal data exchange language. Easy for reading and writing, and easy for machine parsing and generation. Simply put, JSON can convert a set of data represented in a JavaScript object to a string, and then it can be easily passed between functions, alternatively, the string is transmitted from the Web Client to the server in an asynchronous application.

Ii. Ajax interface call

Frontend and backend separation means that the frontend and backend communicate with each other using JSON, and the two development teams use APIs as the contract for interaction, then, in an asynchronous application, the string is transmitted from the Web Client to the server. This part of learning is how to initiate an Ajax request from the front-end to the background, and then update the front-end page after receiving the response from the server.

Iii. php background

PHP is a popular general scripting language and is especially suitable for web development. Php has the following features:

1. cross-platform, superior performance, and cost-effective combination 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 PostgreSQL or Oracle to support N types of databases. (N> = 10)

2. The syntax is simple. It is easy to learn C and Perl and is similar to ASP. There are mature development tools, such as NuPHPed or Zend Studio, and Eclipse can be used on the Linux platform.

3. Currently, all mainstream technologies are supported, such as WebService, Ajax, XML, and so on.

4. There are many mature frameworks, such as the Framework Supporting MVC: phpMVC and the event-driven framework like ASP.net: Prado. It supports fast development frameworks similar to Ruby On Rails: cake and so on, enough to meet your application needs.

5. PHP 5 has a mature object-oriented system that can meet basic object-oriented requirements. Suitable for developing large projects.

This part mainly learns how to build a php server, master the basic syntax of PHP, generate a dynamic web page through php, and Master How to Use php to complete a standardized interface, return JSON data to the foreground.

Iv. Database


Databases are warehouses that organize, store, and manage data according to data structures. Each Database has one or more different APIs for creation, access, and management, search for and copy the stored data. We can also store data in files, but reading and writing data in files is relatively slow.

MySQL is a relational database management system developed by MySQL AB in Sweden and currently belongs to Oracle. MySQL is an associated database management system that stores data in different tables rather than in a large warehouse. This increases the speed and flexibility.

• Mysql is open-source, so you do not need to pay extra fees.

• Mysql supports large databases. It can process large databases with tens of millions of records.

• MySQL uses the standard SQL data language format.

• Mysql can be deployed on multiple systems and supports multiple languages. These programming languages include C, C ++, Python, Java, Perl, PHP, Eiffel, Ruby, and Tcl.

• Mysql has good support for PHP, which is currently the most popular Web development language.

• MySQL supports large databases, 50 million record data warehouses, 32-bit system table files support a maximum of 4 GB, and 64-bit systems support a maximum of 8 TB table files.

This part mainly learns to add, delete, modify, and query operations in data, and finally access the data in the data through php, and then use it for the foreground through response processing.

V. Ajax cross-Origin

In work, AJAX is required to request requests under other domain names, but access is rejected because AJAX can only access local resources based on security considerations, cross-origin access is not allowed.

Solution 1:

"XHR2" stands for "XMLHttpRequest Level2" is a method provided by html5. it provides good support for cross-origin access and has some new features.

* Versions earlier than IE10 are not supported.

* You only need to add the following code to the server header:

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

Solution 2:

JSONP (JSON with Padding) is an unofficial protocol that allows the server to integrate Script tags to return to the client, cross-origin access is implemented through javascript callback (this is only a simple implementation form of JSONP ).

Due to the restrictions of the same-origin policy, XmlHttpRequest only allows requests to resources of the Current Source (domain name, protocol, Port). To implement cross-origin requests, you can use the script tag to implement cross-origin requests, then, the server outputs JSON data and executes the callback function to resolve cross-Origin data requests.

Summary

The above is an example of Ajax asynchronous request technology introduced by xiaobian. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.