1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| $.ajax({ url: '/test', success: function (result) { console.log(result); } });
$.ajax({ url: '/test', method: 'POST', success: function (result) { console.log(result); } });
$.ajax({ url: '/test', data: { a: 10 }, success: function (result) { console.log(result); }, error: function (xhr, status, error) { console.log(error); } });
$.ajax({ url: '/test', headers: { contentType: 'application/json' }, method: 'POST', data: JSON.stringify({ a: 10 }), success: function (result) { console.log(result); } });
$.get(url, data, callback); $.post(url, data, callback);
fetch(url, { headers: { 'content-type': 'application/x-www-form-urlencoded' }, method: 'POST', body: 'a=1&b=2&c[]=a&c[]=b' }) .then((res) => res.json()) .then((data) => console.log(res)) .catch((e) => {});
fetch(url, { headers: { 'content-type': 'application/json' }, method: 'POST', body: JSON.stringify({ a: 100 }) }) .then((res) => res.json()) .then((data) => console.log(res)) .catch((e) => {});
axios({ url: 'http://localhost', method: 'POST', data: { a: 1 } }).then((res) => console.log(res.data));
axios({ url: 'http://localhost', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, data: 'a=1&b=2&c[]=a&c[]=b' }).then((res) => console.log(res.data));
axios.post(url, data).then(callback);
function XMLHttpRequestAjax(method, url, callback, data, flag) { var xhr; flag = flag || true; method = method.toUpperCase(); if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else { xhr = new ActiveXObject('Microsoft.XMLHttp'); } xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { callback(xhr.responseText); } };
if (method == 'GET') { var date = new Date(), timer = date.getTime(); xhr.open('GET', url + '?' + data + '&timer' + timer, flag); xhr.send(); } else if (method == 'POST') { xhr.open('POST', url, flag); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.send(data); } }
|