Can one replace xhr.onreadystatechange with xhr.onload for AJAX calls?

前端 未结 4 1019
星月不相逢
星月不相逢 2020-12-08 06:30

I need to support major modern browsers only (IE10+, FF, Chrome, Safari)

Can I make this substitution as I want to simplify my code base:

From:

4条回答
  •  醉酒成梦
    2020-12-08 06:44

    maybe you take a look at this one and a look at W3C: XMLHttpRequest it's the same if your browser supports xhr.onload. Requires XMLHttpRequest 2)

    You can also write a wrapping function that emulates xhr.onload if it's not present. (I think you need to override XMLHttpRequest.prototype.onload = function(args){//calling onreadystatechanges somehow}). If you only support modern browsers using xhr.onload should be available - the best solution is using a framework (like jquery or mootools that provides wrapping functionality for that.

提交回复
热议问题