控制台ajax post请求

937 阅读1分钟

1.  let data = {"condition":{"field":"xxx"}}

2. let xmlhttp = new XMLHttpRequest();

3. xmlhttp.open('post',url,true);

4. xmlhttp.setRequestHeader("Content-type", "application/json");

    GET请求 -> xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

5. xmlhttp.open(JSON.stringfy(data));

6. xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 &&      xmlhttp.status == 200) { if(JSON.parse(xmlhttp.responseText).code === "200") {  console.log(JSON.parse(xmlhttp.responseText)) } } } ;

7. xmlhttp.onreadystatechange();


***get请求修改data 为字符串格式; 头信息 以及 xmlhttp.open(data)