Asynchronous JavaScript and XML (AJAX) Introduction

计组实验4 控制冒险与分支预测 目录前言实验内容背景知识分支预测技术⭐阻塞周期计算方法不开启 BTB开启 BTBpart 1 矩阵乘法与优化未开启 BTB 的分析开启 BTB 的分析part 2 设计代码使 BTB 无效part 3 循环展开优化矩阵乘法未开启 BTB开启 BTB结束语结论 前言 上一篇博客:计组实验3 mips冒险之流水线冒险 摸了半个月了。。。咕咕咕 今天来写计组实验 4 这个实验非常简单,就是有点难。 这个实验比较容易算错,或者是被模拟器出人意料的结果搞的神神叨叨的,所以今天来记录并且详细分析该实验。 注:请务必阅 阅读详情

AJAX is not a new programming language, but a technique for creating better, faster, and more interactive web applications. With AJAX, your JavaScript can communicate directly with the server, using the JavaScript XMLHttpRequest object. With this object, your JavaScript can trade data with a web server, without reloading the page. AJAX uses asynchronous data transfer (HTTP requests) between the browser and the web server, allowing web pages to request small bits of information from the server instead of whole pages. The AJAX technique makes Internet applications smaller, faster and more user-friendly. AJAX is a browser technology independent of web server software.

AJAX, or transmission of information through the JavaScript DOM, isn't going anywhere. Web 2.0 is clearly an exciting thing for people - even if they don't know what it is.

AJAX is based on the following web standards:

  • JavaScript
  • XML
  • HTML
  • CSS

The web standards used in AJAX are well defined, and supported by all major browsers. AJAX applications are browser and platform independent.

AJAX is About Better Internet Applications

Web applications have many benefits over desktop applications; they can reach a larger audience, they are easier to install and support, and easier to develop. However, Internet applications are not always as "rich" and user-friendly as traditional desktop applications. With AJAX, Internet applications can be made richer and more user-friendly.

 

AJAX Http Requests

AJAX Uses HTTP Requests

In traditional JavaScript coding, if you want to get any information from a database or a file on the server, or send user information to a server, you will have to make an HTML form and GET or POST data to the server. The user will have to click the "Submit" button to send/get the information, wait for the server to respond, then a new page will load with the results. Because the server returns a new page each time the user submits input, traditional web applications can run slowly and tend to be less user-friendly. With AJAX, your JavaScript communicates directly with the server, through the JavaScript XMLHttpRequest object With an HTTP request, a web page can make a request to, and get a response from a web server - without reloading the page. The user will stay on the same page, and he or she will not notice that scripts request pages, or send data to a server in the background.

The XMLHttpRequest Object

By using the XMLHttpRequest object, a web developer can update a page with data from the server after the page has loaded! AJAX was made popular in 2005 by Google (with Google Suggest). Google Suggest is using the XMLHttpRequest object to create a very dynamic web interface: When you start typing in Google's search box, a JavaScript sends the letters off to a server and the server returns a list of suggestions. The XMLHttpRequest object is supported in Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0 / Firefox, Opera 8+, and Netscape 7.

Common XMLHttpRequest Object Methods

MethodDescription
abort()Stops the current request
getAllResponseHeaders()Returns complete set of headers (labels and values) as a string
getResponseHeader("headerLabel")Returns the string value of a single header label
open("method", "URL"[, asyncFlag[, "userName"[, "password"]]])Assigns destination URL, method, and other optional attributes of a pending request
send(content)Transmits the request, optionally with postable string or DOM object data
setRequestHeader("label", "value")Assigns a label/value pair to the header to be sent with a request

Common XMLHttpRequest Object Properties
PropertyDescription
onreadystatechangeEvent handler for an event that fires at every state change
readyStateObject status integer:
0 = uninitialized
1 = loading
2 = loaded
3 = interactive
4 = complete
responseTextString version of data returned from server process
responseXMLDOM-compatible document object of data returned from server process
statusNumeric code returned by server, such as 404 for "Not Found" or 200 for "OK"
statusTextString message accompanying the status code

AJAX Browser Support

The keystone of AJAX is the XMLHttpRequest object. Different browsers use different methods to create the XMLHttpRequest object. Internet Explorer uses an ActiveXObject, while other browsers uses the built-in JavaScript object called XMLHttpRequest.

AJAX Example

Your First AJAX Application

To understand how AJAX works, we will create a small AJAX application. First, we are going to create a standard HTML form with two text fields: username and time. The username field will be filled in by the user and the time field will be filled in using AJAX. The HTML file will be named "testAjax.htm", and it looks like this (notice that the HTML form below has no submit button!):

<html>
<body>
<script type="text/javascript"> function ajaxFunction()
{ var xmlHttp;
try
{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }
catch (e)
{ // Internet Explorer try
{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e)
{ try
{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e)
{ alert("Your browser does not support AJAX!"); return false; } } } } </script>
<form name="myForm">
Name: <input type="text" name="username" />
Time: <input type="text" name="time" />
</form>
</body>
</html>
Example explained: First create a variable xmlHttp to hold the XMLHttpRequest object. Then try to create the object with XMLHttp=new XMLHttpRequest(). This is for the Firefox, Opera, and Safari browsers. If that fails, try xmlHttp=new ActiveXObject("Msxml2.XMLHTTP") which is for Internet Explorer 6.0+, if that also fails, try xmlHttp=new ActiveXObject("Microsoft.XMLHTTP") which is for Internet Explorer 5.5+ If none of the three methods work, the user has a very outdated browser, and he or she will get an alert stating that the browser doesn't support AJAX. Note: The browser-specific code above is long and quite complex. However, this is the code you can use every time you need to create an XMLHttpRequest object, so you can just copy and paste it whenever you need it. The code above is compatible with all the popular browsers: Internet Explorer, Opera, Firefox, and Safari. The next chapter shows how to use the XMLHttpRequest object to communicate with the server.

AJAX - The XMLHttpRequest Object

The onreadystatechange Property

After a request to the server, we need a function that can receive the data that is returned by the server. The onreadystatechange property stores the function that will process the response from a server. The following code defines an empty function and sets the onreadystatechange property at the same time:

xmlHttp.onreadystatechange=function() { // some code here }

The readyState Property

The readyState property holds the status of the server's response. Each time the readyState changes, the onreadystatechange function will be executed.
Here are the possible values for the readyState property:

  • 0 - The request is not initialized
  • 1 - The request has been set up
  • 2 - The request has been sent
  • 3 - The request is in process
  • 4 - The request is complete

xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { // some code here } }

The responseText Property

The data sent back from the server can be retrieved with the responseText property.

xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.myForm.time.value=xmlHttp.responseText; } }

AJAX - Request a Server

AJAX - Sending a Request to the Server

To send off a request to the server, we use the open() method and the send() method. The open() method takes three arguments. The first argument defines which method to use when sending the request (GET or POST). The second argument specifies the URL of the server-side script. The third argument specifies that the request should be handled asynchronously. The send() method sends the request off to the server. If we assume that the HTML and JSP file are in the same directory, the code would be:

xmlHttp.open("GET","trustdir.jsp",true); xmlHttp.send(null);
Now we must decide when the AJAX function should be executed. We will let the function run "behind the scenes" when the user types something in the username text field:
<form name="myForm">
Name: <input type="text" name="username" οnkeyup="ajaxFunction();"/>
Time: <input type="text" name="time" />
</form>

AJAX - The Server-Side Script

AJAX - The Server-Side JSP Script

Now we are going to create the script that displays the current server time. The responseText property (explained in the previous chapter) will store the data returned from the server. Here we want to send back the current time. The code in "trustdir.jsp" looks like this:

<% out.print("Now: "+new java.util.Date()); %>

AJAX - Milliseconds to Date Java converter

Below example to convert milliseconds from January 1st 1970 to date format. Type in the text field any number:

 

Server side

/ajax/timestamp.jsp
<%@ page import="java.util.Date" %>
<%
try {
String t = request.getParameter("t");
if (t==null | t.trim().length()==0) t="0";
java.util.Date dt = new Date(Long.parseLong(t));
out.print(dt.toString());
} catch (Exception e) {
out.print("Invalid input");
}
%>

Client side

<html>
<head>
<script type="text/javascript">
var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);

function GetXmlHttpObject() {
var xmlHttp=null;
try {
xmlHttp=new XMLHttpRequest();
} catch (e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

function ajaxConverter() {
var xmlHttp = GetXmlHttpObject();

xmlHttp.onreadystatechange=function() {
if(xmlHttp.readyState==4) {
var adDiv;
if(ie) adDiv=eval('document.all.divConverter.style');
else if(ns) adDiv=eval('document.layers["divConverter"]');
else if(w3) adDiv=eval('document.getElementById("divConverter").style');
if (xmlHttp.responseText!="") {
document.getElementById("divConverter").innerHTML=xmlHttp.responseText;
if (ie||w3) {
adDiv.visibility="visible";
adDiv.display="";
} else
adDiv.visibility ="show";
}
}
}

xmlHttp.open("GET","/ajax/timestamp.jsp?t="+document.frmConverter.t.value,true);
xmlHttp.send(null);
}
</script>
</head>
<body>
<form name="frmConverter">
<table>
<tr>
<td><input type="text" name="t" style='border:1px solid gray;font-size:13px;' value="" οnkeyup="ajaxConverter()"></td>
<td><div id="divConverter" style="display:none;visibility:hidden;color:blue;font-size:13px;font-weight:bold;"></div></td>
</tr>
</table>
</form>
</body>
</html>

AJAX Disadvantages

  • One big disadvantage of using AJAX is security. Often times developers do not put checks on the data coming into the server - they assume that it's coming from their own website.
  • AJAX does not play well in encrypted environments. AJAX relies on plain text transmission (nothing but text can be transmitted through AJAX anyways), and so encrypted this stream and having the server-side program deal with it presents a large problem.
  • Development time. Building an AJAX application from scratch is actually fairly easy, but it does take longer than building one that uses standard post-backs. As well, the developers require a fairly good knowledge of JavaScript to be able to make it usable.

 

Bandwidth Savings

In applications that have a significant part of each page containing content that is identical in multiple page requests, using AJAX-style methods to update only the relevant parts of a web page can bring significant bandwidth savings. Using less than 100 lines of javascript, we were able to quickly convert an existing web application to use AJAX page-update methods to drastically reduce (>60%) the bandwidth requirements of our sample application.
It is important to note that the application converted in our test was ridiculously simple. Achieving the same bandwidth reduction on a sophisticated application will likely not be as easy, if it is possible at all. However, when applied to extremely large-scale applications or applications with very tight bandwidth considerations, savings of 10% could bring a hefty cost savings.



From  http://www.vicconsult.com/tips/ajax.html

华为 MetaERP 财务模块的核心业务对象,按子模块与架构维度分类,以表格呈现,适配架构设计与实施落地 华为MetaERP财务模块基于4A架构(业务/应用/数据/技术)与TOGAF框架,实现业财一体化与全球合规。业务架构涵盖组织模型与核心流程,应用架构支撑财务操作,数据架构确保数据一致性,技术架构提供高性能技术底座。模块覆盖总账、应收应付、资产等子模块,支持多组织、多币种、多准则核算,通过实时会计引擎实现"交易即核算"。4A架构与TOGAF框架对应,实现业务能力、应用组件、数据模型与技术栈的深度融合,为华为全球化财务核算提供核心支撑。 阅读详情

相关推荐

uniapp: err = err.replace(this._UNI_INPUT_DIR_REG, ‘UNI_TypeError: err.replace is not a function问题修复

问题:uniapp的依赖包出现了问题,需要升级解决办法:升级uniapp依赖包,下载"semver"和”@dcloudio/uni-i18n“两个包,本地锁定postcss为7版本,就解决了。

py_boy的博客 1453

ajax技术英文文献,Introduction to Ajax

摘要:Ajax is a term coined by Jesse James Garrett of Adaptive Path to describe the asynchronous client-to-server communication that is made possible using the XMLHttpRequest object, which is provided b...

weixin_35316459的博客 417

7-1 链式基数排序 (20 分)

7-1 链式基数排序 (20 分) 实现链式基数排序,待排序关键字n满足1≤n≤1000,最大关键字数位≤5。 输入样例: 第一行输入待排序个数n(1≤n≤1000),再输入n个数(n的数位≤5)。 10 278 109 63 930 589 184 505 269 8 83 输出样例: 输出每趟分配-收集后链表中的关键字,趟数为序列中最大值的数位(如样例中930的数位为3),每行结尾有空格。 930 63 83 184 505 278 8 109 589 269 505 8 109 930 63 26

OwemShu的博客 4236

introduction to Ajax

AJAX  means Asynchronous(异步的) JavaScript and XML. Remember on sentence: It is possible to update parts of a web page, without reloading the whole page. How Ajax works? browser An

ganggang112800的专栏 701

手把手教你用gym训练宇树GO2机器人模型(附完整配置文件)

本文提供了一份详细的实战指南,教你如何使用Gym框架为宇树GO2四足机器人搭建强化学习训练环境。文章深入解析了环境配置、参数调试、奖励函数设置等关键步骤,并分享了避开常见陷阱的经验,旨在帮助开发者高效完成模型训练。

oo7890的博客 322

《C++等级认证CCF-GESP真题解析》专栏总目录

❤️ 专栏名称:《C++等级认证CCF-GESP真题解析》🌸 专栏介绍:中国计算机学会GESP《CCF编程能力等级认证》C++编程(1~8级)历届真题解析。🚀 订阅专栏:订阅后可阅读专栏内所有真题解析,真题持续更新中,欢迎订阅!

人生就是一个不断学习的过程 6287

An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NET

An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NETAtif Aziz, Scott MitchellFebruary 2007Applies to:   JSON   AjaxSummary: This article discusses JavaScript Object

aspgreener的专栏 2326

仿真学习系列(四十三):Sigrity仿真之平面谐振分析

在 SIGRITY 中,平面谐振分析(Plane Resonance Analysis)是一种用于分析信号完整性(SI)问题的高级仿真方法,尤其关注于层间电磁波的传播、谐振现象和信号衰减等问题。平面谐振分析通常用于电源分配网络(PDN)、信号线和参考平面之间的相互作用。本文将详细介绍如何在 SIGRITY 中进行平面谐振分析,并提供一些实用的分析方法与步骤,帮助工程师们识别和优化可能存在的设计问题。

案例文章,高速信号 480

AJAX——Introduction和最简单的AJAX例子

AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术。 AJAX不是一种新的编程语言,而是一种用于创建更好更快以及交互性更强的Web应用程序的技术。 使用Javascript向服务器提出请求并处理响应而不阻塞用户!核心对象XMLHTTPRequest。通过这个对象,您的 JavaScript

ps_zhanglei的专栏 465

【雷达成像】基于matlab SAR雷达成像仿真【含Matlab源码 3750期】

SAR雷达成像仿真 完整的代码,方可运行;可提供运行操作视频!适合小白!

订阅付费专栏Matlab(奶茶价版),可赠送奶茶价版付费专栏指定代码1份; 1084

材料仿真软件:Quantum Espresso_(15).声子与振动模式计算

通过上述步骤和代码示例,您应该能够使用 Quantum Espresso 进行声子与振动模式的计算。声子计算是材料科学研究中的重要工具,可以帮助我们更好地理解和设计材料的性能。希望本节内容对您有所帮助。

kkchenjj的博客 1181

Introduction to Ajax for Page Authors

Introduction to Ajax for Page Authors By Ed Ort, January 2007   Contents - Ajax and You - What You Need to Know About Ajax - Ajax and JavaScript Technology - Adding Ajax to a Web Page - Using Ajax-Ena...

zengjinliang的专栏 283

FPGA 学习笔记:Vivado 配置IO引脚约束

FPGA 学习笔记:Vivado 配置IO引脚约束

坚韧与专注 2万+

AJAX教程02 AJAX Introduction(From w3schools)译读

What you should already know Before you continue you should have a basic understanding of the following: HTML / XHTMLJavaScript If you want to study these subjects first, find the tutorials on our Hom...

weixin_30319153的博客 108

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

An introduction to JSON

JSON=Javascript object notation and is lightweight data-interchange format It is native to js so nothing extra needing to do to make it work with javascript; It is great to store data for javascript

Schen6 Online Life 807

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Introduction to Ajax for Java Web Applications

This document provides an introduction to Ajax and demonstrates some of the features in the NetBeans IDE that allow you to program faster and more efficiently when working with Ajax-related technologi

lvtouyayayaya的专栏 1384

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

JSON Introduction

Introduction As we know Ajax is a web development technology that makes the server responses faster by enabling the client-side scripts to retrieve only the required data from the server without...

peifei1234的博客 217

ajax框架dwr的配置及使用introduction

1.引入dwr.jar包 2.在web.xml里配置dwr的servlet [code="java"] dwr-invoker org.directwebremoting.servlet.DwrServlet debug true dwr-invoker /dwr/* [/code] 3.通过一...

搜索-gcgmh 174

http://www.developertutorials.com/learn-javascript/introduction-to-javascript-2588.php

http://www.developertutorials.com/learn-javascript/introduction-to-javascript-2588.phpLearn JavaScript JavaScript Tutorial Introduction to JavaScript JavaScript Getting Started JavaScript

277

用到jQuery的web2.0技术(译)

Web2.0中的jQuery和Ajax技术   原作者:Cornelia Györödi,  Robert Györödi, George Pecherle, Tamas Lorand,  Roșu Alin 原文连接:http://wenku.baidu.com/view/f53392a50029bd64783e2cec.html 翻译:Ansel(凌志鸿) 指导老师:杨金民 摘要:

lwpaaa的专栏 1107

htb academy笔记-module-Introduction to Web Applications(二)

可用来网页和mobile开发,网页开发时更多用于前端,也可用于后端来开发整个web app如NodeJS,也可用来自动化发送http requests和后端交互,如Ajax;还有前文提到的css动画也需要js主流浏览器都可以直接运行js。

weixin_51439723的博客 1064

(附源码)基于springboot的物流配货管理系统的设计与实现-毕业设计 课程设计 250858

物流配货管理系统主要功能模块包括:库存货物、分类信息、货物入库、货物出库、车辆分类、车辆、订单中心、车辆路线、顶大追踪、订单发货、系统管理员、配货管理员、车辆管理员等模块,采取面对对象的开发模式进行软件的开发和硬体的架设,能很好的满足实际使用的需求,完善了对应的软体架设以及程序编码的工作,采取Mysql作为后台数据的主要存储单元,采用springboot技术、vue.js语言、ajax等技术进行业务系统的编码及其开发,实现了本系统的全部功能.本次报告,首先分析了研究的背景、作用、意义,为研究工作的合理性打下

Q_3461074420的博客 2561

Introduction to HTML

In This Article         (CodeCademy上一些相关的扩展阅读) History of HTML What is HTML? Elements — the basic building blocks Tags Attributes Named character references Comments and doctype A complete but...

seeleday的博客 557

【课程设计】springboot实验室预约管理系统 毕业设计 261141

注册用户的功能如下: 注册:点击注册输入具体信息,设置密码注册用户。 登录:根据账号密码进行篮球场地系统登录操作。 维护个人信息:用户因个人信息的变更可以随时修改自己注册信息。 实验室信息:系统发布实验室信息(包括实验室地址、名称。对应专业、实验室配置等)便于用户浏览。 学生预约:学生根据自己的需求选实验室以及预约的时间时间等进行预约提交。 授课预约:老师根据自己的授课需求对应选择实验室,进行预约提交。 器材租赁:用户可以提交器材租赁申请。 成果展示:发布实验成果信息,(包括实验标题、对应专业、学生、实验详

WeiXin_DZbishe的博客 3147

(附源码)spring boot考试系统-毕业设计 课程设计 191015

(1)考试系统,考试信息维护,用户维护和个人信息维护管理员可以往题中添加考题,修改错误试题和删除无用试题,考试系统包括单选题管理(单选题添加、删除、修改)、判断题管理(判断题添加、删除、修改)、多选题管理(多选题添加、删除、修改)。 (2)考试信息的维护 考试信息的维护主要是对于考试设置信息进行维护,这些信息主要是考试总时间,试题数量,各试题分值的分布等。 (3)用户维护 系统管理员可以对用户信息(包括考生信息)进行增,删,改查操作。 (4)个人信息维护 管理员也可以对自己的基本信息的维护。

Q_3461074420的博客 4135

【课程设计】(附源码)springboot课程在线考试系统 毕业设计655127

课程在线考试系统主要功能模块包括登录、用户管理、交流中心、论坛分类、考试资讯、资讯考试,采取面对对象的开发模式进行软件的开发和硬体的架设,能很好的满足实际使用的需求,完善了对应的软体架设以及程序编码的工作,采取MySQL作为后台数据的主要存储单元,采用springboot框架、Java技术、Ajax技术进行业务系统的编码及其开发,实现了本系统的全部功能。本次报告,首先分析了研究的背景、作用、意义,为研究工作的合理性打下了基础。针对课程在线考试系统的各项需求以及技术问题进行分析,证明了系统的必要性和技术可行性

Biye_Design的博客 6101
上一篇: CAPTCHA(验证码)的来源与作用
下一篇: ASP.NET DropDownList列表项添加前导空格(Leading Space)的两种方法
Jason_Steven
博客等级 码龄20年 14粉丝 31原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值