0%
jQuery
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
| $.ajax({ async: true, url: "url", method: "POST", dataType: "json", data: { data1: "a", data2: "b", data3: "c" }, beforeSend: function () { }, success: function (result) { }, error: function () { }, complete: function () { } });
|
JavaScript
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
|
let xhr = new XMLHttpRequest();
xhr.open('POST', 'http://example.com');
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(formData);
xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { console.log(xhr.responseText); } };
xhr.upload.onprogress = function (e) { if (e.lengthComputable) { let percent = e.loaded / e.total * 100 + "%"; document.getElementById('percent').style.width = percent; document.getElementById('percent').innerText = percent; } else { alert("文件不支持上传中的进度监测"); } };
xhr.upload.onload = function () {
};
|
Ajax
XMLHttpRequest