Analysis and application of Ajax technology in 13 springboot project

Jason 2020-11-10 12:44:31
analysis application ajax technology springboot

Ajax Technical introduction

Background analysis ?

Today, with the rapid development of Internet , Conventional WEB application , For high concurrency 、 High performance 、 The demand for high reliability is imminent . Single thread mode of client-side and server-side interaction mode has been unable to meet the needs of the current stage . We need to be asynchronous 、 Load on demand to get data from the server and refresh in time , To improve the user experience , therefore Ajax The birth of Technology .

Ajax What is it? ?

Ajax (Asynchronous JavaScript and XML) It's a kind of Web Application client technology , You can use client script (javascript) Asynchronous communication with server applications ( Multiple threads can interact with the server at the same time ), And after getting the server-side data on demand , Local refresh can be done , In order to improve the data response and rendering speed .

Ajax Application scenarios ?

Ajax The biggest advantage of technology is the underlying asynchronous , Then partial refresh , To improve the user experience , This technology is now well used in many projects , for example :

  • Commodity system .
  • Evaluation system .
  • Map system .
  • …..

AJAX You can just send and retrieve the necessary data to the server , And in the client side JavaScript Processing the response from the server . This reduces the amount of data exchanged between the server and the browser , The server responds faster . but Ajax Technology also has disadvantages , The biggest disadvantage is that cross domain access is not available directly .

Ajax Application model analysis ?

Ajax Quick start

Ajax Request response process analysis

The traditional way is web Request and response ( The client has to wait for the response ), As shown in the figure :


Ajax How to request and respond ( The key is that the client does not block ), As shown in the figure :


Ajax Programming steps and template code analysis

Ajax The basic steps of coding ?( The key is ajax The entrance of Technology -XMLHttpRequest-XHR object )

First step : be based on dom Event creation XHR object
The second step : stay XHR Register state listener on object ( Monitor the communication process between client and server )
The third step : Establish a connection with the server ( Specify request method , request url, Synchronous or asynchronous )
Step four : Send a request ( Pass the request data to the server )

Ajax The template code for the encoding process is as follows :

var xhr=new XMLHttpRequest();

SpringBoot project Ajax Introduction analysis of technology application

First step : Create project module, As shown in the figure :


The second step : add to Spring web rely on , The code is as follows :


The third step : establish AjaxController Handle client requests , The code is as follows :

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
public class AjaxController {
public String doAjaxGet01(){
return "Response Result Of Ajax Get Request 01 ";

Step four : In the project static Under the table of contents , Create a page ajax-01.html, The code is as follows :

html The element code is as follows :

<h1>The Ajax 01 Page</h1>
<legend>Ajax asynchronous Get request </legend>
<button onclick="doAjaxGet01()">Ajax Get Request</button>
<span id="result">Data is Loading ...</span>

javascript The script code is as follows :

function doAjaxGet01(){
//debugger// Client breakpoints ( This breakpoint takes effect by opening the console )
//1. establish XHR object (XmlHttpRequest)-Ajax The entry object of the application
let xhr=new XMLHttpRequest();
//2. stay XHR Register state listener on object ( Get the server response results and update to the page result Location )
xhr.onreadystatechange=function(){// Event handler ( The communication state between the client and the server changes This function is executed when )
//readyState==4 Indicates that the server responds that the client data has been received .
if(xhr.status==200){//status==200 Indicates that the request processing is OK
//3. Establish a connection with the server ( Specify request method , request url, asynchronous )"GET","http://localhost/doAjaxGet01",true);//true On behalf of the asynchronous
//4. Send a request to the server
xhr.send(null);//get request send Methods do not transfer data or write a null
console.log("===main thread===")
// If it is an asynchronous client, the execution is finished send Will continue down .

Step five : start-up Tomcat Service and access test analysis .


Click on Ajax Get Request Button , Detect page data updates .

Step six : During the start-up and access process Bug analysis

  • There is no response when you click the button


  • The object accessing the specified property does not exist


  • Cross domain access


Ajax Basic business implementation

Basic business description

The key code design and implementation of the server

Client key code design and implementation

Ajax Advanced technology implementation

Ajax Encapsulation of code

Ajax The implementation of small programming framework

Ajax Technology in Jquery Application in

Jquery brief introduction

Jquery Commonly used ajax Function analysis

Jquery in Ajax The basic application implementation of function

summary (Summary)

This chapter mainly introduces Ajax What is it? 、 Application scenarios 、 The communication model between client and server 、ajax The basic steps of programming 、 Packaging process and ajax Technology in some JS Applications in the framework, etc , And focus on the analysis in ajax Some debugging skills in the coding process .


  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云