XMLHttpRequest 中的 onload 是否等于 readyState==4? [英] Is onload equal to readyState==4 in XMLHttpRequest?
本文介绍了XMLHttpRequest 中的 onload 是否等于 readyState==4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对 xhr 返回事件感到困惑,据我所知,onreadystatechange --> readyState == 4 和 onload 之间没有太大区别,是真的吗?
I am confuse about the xhr return event, as I can tell, there are not so much different between onreadystatechange --> readyState == 4 and onload, is it true?
var xhr = new XMLHttpRequest();
xhr.open("Get", url, false);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4)
{
/* do some thing*/
}
};
xhr.send(null);
或
xhr.onload = function() { /* do something */ }
推荐答案
应该是一样的.onload
是在 XMLHttpRequest 2 中添加的,而 onreadystatechange
从原始规范开始就已经存在了.
It should be the same thing. onload
was added in XMLHttpRequest 2 whereas onreadystatechange
has been around since the original spec.
这篇关于XMLHttpRequest 中的 onload 是否等于 readyState==4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文