简体   繁体   中英

to do the functionality of jquery `success` function by pure js?

$.ajax({
            success: function (returns) {
                if (returns)
                    alert("returned successfully");
            }
        });

how can I turn this jquery function to pure js?I'm new in js by the way!

On your XMLHttpRequest object add a listener on onreadystatechange :

xhr.onreadystatechange = function() {
  if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
    option.success(xhr.responseText)
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM