Skip to content

Commit

Permalink
Merge pull request madrobby#282 from elsigh/zepto
Browse files Browse the repository at this point in the history
---

Conflicts:
	README.rdoc
  • Loading branch information
madrobby committed Dec 4, 2011
2 parents 92c8c6d + 6acd08d commit c2580e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -285,6 +285,7 @@ $.ajax({
url: '/foo', // defaults to window.location
data: {name: 'Zepto'}, // can be a string, object or result of serializeArray()
dataType: 'json', // what response type you accept from the server ('json', 'xml', 'html', or 'text')
async: true, // set async flag (true by default)
success: function(body) { ... }, // body is a string (or if dataType is 'json', a parsed JSON object)
error: function(xhr, type) { ... } // type is a string ('error' for HTTP errors, 'parsererror' for invalid JSON)
})
Expand Down
3 changes: 2 additions & 1 deletion src/ajax.js
Expand Up @@ -253,7 +253,8 @@
}
};

xhr.open(settings.type, settings.url, true);
var async = 'async' in settings ? settings.async : true;
xhr.open(settings.type, settings.url, async);

if (settings.contentType) settings.headers['Content-Type'] = settings.contentType;
for (name in settings.headers) xhr.setRequestHeader(name, settings.headers[name]);
Expand Down
13 changes: 12 additions & 1 deletion test/ajax.html
Expand Up @@ -166,9 +166,10 @@ <h1>Zepto Ajax unit tests</h1>
MockXHR.last = this;
}
MockXHR.prototype = {
open: function(method, url) {
open: function(method, url, async) {
this.method = method;
this.url = url;
this.async = async;
},
setRequestHeader: function(name, value) {
this.headers.push({ name: name, value: value });
Expand Down Expand Up @@ -486,6 +487,16 @@ <h1>Zepto Ajax unit tests</h1>
t.assertEqual('timeout', status);
});
}, 40);
},

testAsyncDefaultsToTrue: function(t) {
$.ajax({ url: '/foo' });
t.assertTrue(MockXHR.last.async);
},

testAsyncFalse: function(t) {
$.ajax({ url: '/foo', async: false });
t.assertFalse(MockXHR.last.async);
}
});

Expand Down

0 comments on commit c2580e3

Please sign in to comment.