javascript - How do you return a promise? -


i don't understand how return promise. here's i've got far:

post('myprogram.cfm',done)  function done(response) {    log('done')    log(response)  }  	    function post(url,callback) {  	const form = new formdata(document.queryselector('form'))  	fetch(url, {  		method: 'post',  		body: form  	}).then(then)  		.then(callback)  		.catch(fail)  	function then(response) {  		return response.json()  	}  	  	function fail(response) {  		log('fail!')  		log(response)  	}  }

what is:

const promise = post('myprogram.cfm') promise.done(done) 

i think instead of doing then(callback), should return something.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -