How to use the can-connect/helpers/.deferred function in can-connect

To help you get started, we’ve selected a few can-connect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github canjs / can-connect / src / helpers / ajax.js View on Github external
module.exports = function (o) {
	var xhr = $.xhr(), timer, n = 0;
	var deferred = helpers.deferred();

	o = helpers.extend({ userAgent: "XMLHttpRequest", lang: "en", type: "GET", data: null, dataType: "application/x-www-form-urlencoded" }, o);
	if (o.timeout) {
		timer = setTimeout(function () {
			xhr.abort();
			if (o.timeoutFn) {
				o.timeoutFn(o.url);
			}
		}, o.timeout);
	}
	xhr.onreadystatechange = function () {
		if (xhr.readyState === 4) {
			if (timer) {
				clearTimeout(timer);
			}
			if (xhr.status < 300) {