重温AJAX
来源:互联网 发布:债券数据查询 编辑:程序博客网 时间:2024/06/16 19:53
之前了解过AJAX,最近用的比较多,又重新温习一下,简单整理了一下,文中的英文注释全是小编自翻,可能不对或者不够好的地方,欢迎大家指正!
/** * 什么是AJAX * 异步JAVASCRIPT和XML(其中的A表示async,异步的) * @authors enlove (you@example.org) * @date 2017-11-30 10:06:03 * @version $Id$ */function xmload(){var xmlhttp;if(window.new XMLHttpRequest){xmlhttp = new XMLHttpRequest();//create a object of XMLHttpRequest}else {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.onreadystatechange = function(){if(xmlhttp.readyState == 4 && xmlhttp].status == 200){document.getElementById("enlove").innerHTML = xmlhttp.responseText;}}/** *send HttpRequest to server *we can use the function of open and send *the params of open: the first param is the method of sending HttpRequest to server, *there are two methods, one is "GET", and another one is "POST"; the second param is *the url that you store your texts in your server; the last param whose type is boolean, *that true represent "async", false represent "sync" * * attention: function of send(string) only can be used when the method is "POST" */xmlhttp.open("GET","/try/ajax/enlove.txt",true);xmlhttp.send();}/** * GET or POST * compare to POST, GET is faster and easier than POST, and GET can be used at most common, * but please use POST at following: * *can not use cache(to update the file or DB on the server) * *send great amount of data(POST have no limit of data) * *send character that is unknown, POST is stable than GET *//** * above the following examples, the result is posssible caches * to avoid this, please add an unique ID to the url,like that */ xmlhttp.open("GET","/try/ajax/enlove.txt?t="+Math.random(),true); xmlhttp.send(); /** * if you want to send message by GET, please add information to URL */ xmlhttp.open("GET","/try/ajax/enlove.txt?name=Henty&value=ford",true); xmlhttp.open(); /** * if you have necessary to POST data like form of HTML, please use setRequestHeader() to add * HTTP header. then add message that you want to send in function send. */ xmlhttp.open("GET","/try/ajax/enlove.txt",true); xmlhttp.setRequestHeader("content-type", "application/x-www-form-urlencoded");xmlhttp.send(name=Henty&value=ford);/** * for the developers of web, the AJAX is a big progress. It costs too much time to handle the masks on sever. Before AJAX, this can led to the applications stop or hang. * By AJAX, JavaScript have no need to wait the response from server, and * * handle other javascripts when waiting sever's responses * * handle the js when the response is done *//** * Async = true * when the last param of function open is true, please provision(规定) the response at onreadystatechange's stauts. */xmlhttp.onreadystatechange = function(){if(xmlhttp.readyState == 4 && xmlhttp].status == 200){document.getElementById("enlove").innerHTML = xmlhttp.responseText;}}/** * Async = false */xmlhttp.open("GET","/try/ajax/ajax_info.txt",false);xmlhttp.send();document.getElementById("myDiv").innerHTML=xmlhttp.responseText;/** * the event of onreadystatechange * when the requests are sent to server, we need to handle some masks based on response * when the readystate changes, it will trigger the events of onreadystatechange * the attribute of readyState store the status of XMLHttpReuqest. * next is the important attributes of XMLHttpReuqest. */ ________________________________________________________________________________ attributes | description ________________________________________________________________________________ onreadystatechange | when the readystate changes, it will trigger the events of |onreadystatechange ________________________________________________________________________________ readyState | store the status of new XMLHttpRequest, from 0 to 4 | 0: the request is not intialization | 1: the connect to server is establish | 2: the request is recieved | 3: the resquet is handling | 4: the request is done, and response is onready ________________________________________________________________________________ status | 200: OK | 404: the pages are not found ________________________________________________________________________________
阅读全文
0 0
- 重温AJAX
- 重温
- 重温之Struts与Ajax结合向前台传送json数据实现ztree(一次性加载ztree)
- 重温 DOS
- 重温classpath.
- 重温‘心火’
- 重温MVC
- 重温C++
- 重温compiere
- 重温 高考
- 重温struts
- VirtualMemory重温
- 重温MFC.
- 重温“黑客”
- 重温Ubuntu
- 重温经典
- 【ffmpeg重温】
- 重温c++
- [LeetCode] 646. Maximum Length of Pair Chain
- Andrew Ng机器学习笔记week3 逻辑回归
- 开发常用英语词汇
- js构造函数
- 如何了解eclipse中各目录的作用?
- 重温AJAX
- maven POM.xml 标签详解
- JDK不同操作系统的FileSystem(Windows)下篇
- JavaScript隐式类型转换
- 文件上传S3代码收集
- 异或问题(java)
- 算法面试大全
- 机器学习与贝叶斯分类器
- 移动端user-scalable=yes页面,旋转屏幕后重置缩放比例。