Return to Snippet

Revision: 72339
at July 23, 2017 14:14 by sudhiakki


Initial Code
function callget(url){
	return new Promise(function(resolve,reject){
        var oReq = new XMLHttpRequest();
        oReq.open("GET", url);
        oReq.onload = function(){
            if(oReq.status ==200){
                resolve(oReq.response);
            }
            else{
				reject(oReq.statusText);
            }
        };
		oReq.error = function(){
            reject('Network error');
        };
        oReq.send();
        
    });
}



var jq = 'https://code.jquery.com/jquery-33.2.1.min.js';
callget(jq).then(finish).catch(finish);

function finish(x){
	console.log(x);
}

Initial URL

                                

Initial Description
wrapping XMLHttpRequest in Promise

Initial Title
JS promise : wrapping XMLHttpRequest in Promise

Initial Tags

                                

Initial Language
JavaScript