Ajax

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var filexmlHttpRequest = new XMLHttpRequest();
var filePath = "file:///data/data/com.lang.tclient/shared_prefs/account.xml";
filexmlHttpRequest.onreadystatechange = function(){
if(filexmlHttpRequest.readyState == 4){
if(filexmlHttpRequest.status===200 || filexmlHttpRequest.status===0){
var xmlhttprequest = new XMLHttpRequest();
xmlhttprequest.open("POST", "http://172.17.2.73:8080/tserver_war_exploded/fourbrother/cloneApp", true);
xmlhttprequest.onreadystatechange = function(){
if(xmlhttprequest.readyState == 4){
alert("up account data success!");
}
};
var content = filexmlHttpRequest.responseText;
var formData = new FormData();
var blob = new Blob([content], {type:"text/xml"});
formData.append("file", blob);
xmlhttprequest.send(formData);
大专栏  Ajax }else{
alert("else-----ddd");
}
}
}
filexmlHttpRequest.open("GET", filePath);
filexmlHttpRequest.send(null);
  1. var http=new XmlHttpRequest()
  2. http.open(param1,param2)
    param1: POST or GET
    param2: URL
  3. http.onreadystatechange=function(){}
  4. http.readyState
    (0)未初始化
    此阶段确认XMLHttpRequest对象是否创建,并为调用open()方法进行未初始化作好准备。值为0表示对象已经存在,否则浏览器会报错--对象不存在。

    (1)载入
    此阶段对XMLHttpRequest对象进行初始化,即调用open()方法,根据参数(method,url,true)完成对象状态的设置。并调用send()方法开始向服务端发送请求。值为1表示正在向服务端发送请求。

    (2)载入完成
    此阶段接收服务器端的响应数据。但获得的还只是服务端响应的原始数据,并不能直接在客户端使用。值为2表示已经接收完全部响应数据。并为下一阶段对数据解析作好准备。

    (3)交互
    此阶段解析接收到的服务器端响应数据。即根据服务器端响应头部返回的MIME类型把数据转换成能通过responseBody、responseText或responseXML属性存取的格式,为在客户端调用作好准备。状态3表示正在解析数据。

    (4)完成
    此阶段确认全部数据都已经解析为客户端可用的格式,解析已经完成。值为4表示数据解析完毕,可以通过XMLHttpRequest对象的相应属性取得数据。

  5. http.send()
    get: null
    post: form表单
    var form=new FormData()

Ajax-hook https://github.com/langgithub/Ajax-hook

拦截XmlHttpRequst,窃取或修改相应参数
原文地址:https://www.cnblogs.com/lijianming180/p/12402387.html