--- title: XMLHttpRequestEventTarget.onload slug: Web/API/XMLHttpRequestEventTarget/onload translation_of: Web/API/XMLHttpRequestEventTarget/onload ---
XMLHttpRequestEventTarget.onload
是 {{domxref("XMLHttpRequest")}} 请求成功完成时调用的函数。
XMLHttpRequest.onload = callback;
callback
是请求成功完成时要执行的函数。它接收一个 {{domxref("ProgressEvent")}} 对象作为它的第一个参数。this 的值(即上下文)与此回调的 {{domxref("XMLHttpRequest")}} 相同。var xmlhttp = new XMLHttpRequest(), method = 'GET', url = 'https://developer.mozilla.org/'; xmlhttp.open(method, url, true); xmlhttp.onload = function () { // 处理取回的数据(在 xmlhttp.response 中找到) }; xmlhttp.send();
Specification | Status | Comment |
---|---|---|
{{SpecName('XMLHttpRequest', '#handler-xhr-onload')}} | {{Spec2('XMLHttpRequest')}} | WHATWG living standard |
{{Compat("api.XMLHttpRequestEventTarget.onload")}}