1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Document</title>
- </head>
- <body>
- <h3>这是个测试文件</h3>
- </body>
- </html>
- <script>
- function post() {
- var xmlhttp;
- if(window.XMLHttpRequest) {
- xmlhttp = new XMLHttpRequest();
- }else if(window.ActiveXObject) {
- xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
- }
- //回调
- xmlhttp.onreadystatechange = function(){
- if(xmlhttp.readyState == 4) {
- if(xmlhttp.status == 304 || (xmlhttp.status >= 200 && xmlhttp.status < 300)) {
- var renderMessage = JSON.parse(xmlhttp.responseText);
- console.log(renderMessage);
- }
- }
- }.bind(this);
- //请求
- xmlhttp.open('post', '/test', true);
- xmlhttp.setRequestHeader('Content-Type','application/json;charset=utf-8');
- xmlhttp.send(JSON.stringify({id:'12321', params: 'qwe'}));
- }
- function get() {
- var xmlhttp;
- if(window.XMLHttpRequest) {
- xmlhttp = new XMLHttpRequest();
- }else if(window.ActiveXObject) {
- xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
- }
- //回调
- xmlhttp.onreadystatechange = function(){
- if(xmlhttp.readyState == 4) {
- if(xmlhttp.status == 304 || (xmlhttp.status >= 200 && xmlhttp.status < 300)) {
- var renderMessage = JSON.parse(xmlhttp.responseText);
- console.log(renderMessage);
- }
- }
- }.bind(this);
- //请求
- xmlhttp.open('get', '/test?name=213&sex=1', true);
- xmlhttp.setRequestHeader('Content-Type','application/json;charset=utf-8');
- xmlhttp.send();
- }
- </script>
|