Showing posts with label jQuery. Show all posts
Showing posts with label jQuery. Show all posts

12 June 2012

jQuery Deferred for Asynchronous callbacks

jQuery Deferred is a convenient way to perform Asynchronous callbacks.
For example, during the load of a page if you are performing a javaScript operation that takes some time to execute, an asynchronous callback can be used. The page will load without blocking.

jQuery has the $.Deferred() feature that can register multiple callbacks and invoke them.
The deferred.done() adds an handler to be called when the Deferred object is resolved (doneCallbacks).
The deferred.resolve() resolves a Deferred object and calls any doneCallbacks with the given args.

The following code is an example usage:
var deferred = new $.Deferred();

deferred.done(function(message) { 
    // Put the code to execute asynchronously here
    alert(message);
});

deferred.resolve('"hello world!!!"');
There is a lot more about the Deferred Object in the jQuery documentation.

06 April 2009

jQuery Intellisense in VS 2008

I have been working with the jQuery in VS 2008 and I needed jQuery intellisense support.
Since the process in not straightforward, I decided to document it here:
1) Install VS 2008 SP1
2) Install VS 2008 Patch KB958502 to Support "-vsdoc.js" Intellisense Files
You can download it for here
3) Download the jQuery-vsdoc.js from the official download page here
Use the Documentation: Visual Studio link.
4) Save the jquery-vsdoc.js file in the same folder of the jquery.js file in your project and make sure its naming prefix matches the jquery file name
5) There is no intellisense support in user controls (ascx) unless the jQuery.js file is included. Since normally we don't want to include the jQuery file in the ascx there is a workaround:


<% if (false) {%>
<% script src="js/jquery.js" type="text/javascript"><% /script>
<% } %>


For more information:
jQuery Intellisense in VS 2008