Request syncronization

30 views
Skip to first unread message

ffreshblood

unread,
Apr 26, 2012, 10:48:35 AM4/26/12
to Sammy.js
Hello everybody

I need to synchronize ajax request with no blocking. I think Sammy.js
exactly execute all ajax request in ordered way. So i have checked
some source code of Sammy and read documentation for understand how
this synchronization works.

At below, send method of ctx guarantee that this asynchronous request
will be synchronized(ordered), at least this is what i have understood
from documantation.

this.post('/Post/Add', function (ctx) {
ctx.send($.post, ctx.path, { Definition: ctx.params.Definition })
.then(function (data) { });
});

I already use it in this way but sometimes i need to make ajax
requests in anywhere of my website so i need to keep request worked in
ordered way. So do i have to set ctx parameter to global scope and use
it's send method ?

Or Sammy.js provide synronization in out of app for us?

Ramiro

unread,
Apr 27, 2012, 3:42:33 PM4/27/12
to sam...@googlegroups.com
You don't need Sammy's help for this because since jQuery 1.5 you can easily use the Deferred object:
Sammy itself uses this same Deferred principal/object.

So anywhere on your site you can do something like:
$.ajax('/api/example.json')
.done(function(data) {

$.ajax('api/example2.json')
.done(function(data2) {
alert(data +' '+ data2)
})  
})

Good luck.
Reply all
Reply to author
Forward
0 new messages