jQuery Deferred object

15 במאי 2012

Suppose you need to fetch some data from your server by executing 3 different $.ajax requests.Each request brings a different part of the total data. You don't mind in which order the requests complete.Only when the 3 requests are completed successfully you can use the data. In addition, in case one of the method fails you need to execute some error handling code.The naive solution looks something like that:function getAllData(success, error, complete) {     var count = 0;     var errorInvoked = false;     var successInvoked = false;     var completeInvoked = false;     var successHandler = function () {         if (++count == 3) {             success();             successInvoked = true;         }     }     var errorHandler = function () {         if (!errorInvoked) {             error();             errorInvoked = true;         }     }     var completeHandler = function () {         if ((successInvoked || errorInvoked) && !completeInvoked) {             complete();             completeInvoked = true;         }     }     $.ajax({         url: "/GetData1",         type: "GET",         dataType: "json",         success: successHandler,         error: errorHandler,         complete: completeHandler     });     $.ajax({         url: "/GetData2",         type: "GET",         dataType: "json",         success: successHandler,         error: errorHandler,         complete: completeHandler     });     $.ajax({         url: "/GetData3",         type: "GET",         dataType: "json",         success: successHandler,         error: errorHandler,         complete: completeHandler     }); } We are subscribing to the success/error/complete event of each ajax request and when all complete or one fails we execure the appropriate handlersAs you can see the...
no comments

ASP.NET MVC 4 Beta – MSDN Session at Microsoft

14 במאי 2012

Today I delivered yet another MSDN session at Microsoft. This time it was about ASP.NET MVC 4 Beta.The biggest news for this version is a new template project named Single Page Application (SPA).Implementing SPA is now possible using several client libraries like Knockout, upshot and History. Those libraries combined with ASP.NET Web API allow us to write desktop/mobile like application using web technologies.All samples and PPTs introduced during the session can be found hereI hope you enjoyed the session and while reading those words you are already in the middle of MVC 4 installation process ...
3 comments