What happens if I write this jQuery code with native javascript?

Asked 2 years ago, Updated 2 years ago, 76 views

$.ajax({
    url: '/ajax/',
    type: 'get',
    async —false,
    success:function(d){
        console.log(d);
    },
});

javascript jquery

2022-09-30 20:33

1 Answers

If you would like to know the implementation in jQuery, you can view the source at the following site.
http://james.padolsey.com/jquery/#v=1.10.2&fn=jQuery.ajax

To do the same thing simply, use XMLHttpRequest to:

var httpRequest=new XMLHttpRequest();

httpRequest.onreadystatechange=function(){
    if(httpRequest.readyState==4&&httpRequest.status==200){
        // success
        console.log (httpRequest.responseText);
    }
};

httpRequest.open('GET', '/ajax/', false);
httpRequest.send(null);


2022-09-30 20:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.