<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Intelligrape  Groovy &#38; Grails Blogs &#187; jquery</title>
	<atom:link href="http://www.intelligrape.com/blog/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.intelligrape.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 02 Feb 2012 07:48:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
			<title>Intelligrape  Groovy &amp; Grails Blogs</title>
			<url>http://www.intelligrape.com/blog/wp-content/uploads/2011/05/favicon2.ico</url>
			<link>http://www.intelligrape.com/blog</link>
			<width></width>
			<height></height>
			<description></description>
		</image>		<item>
		<title>JQuery : create URL query string from JSON/Array</title>
		<link>http://www.intelligrape.com/blog/2011/05/04/jquery-create-url-query-string-from-jsonarray/</link>
		<comments>http://www.intelligrape.com/blog/2011/05/04/jquery-create-url-query-string-from-jsonarray/#comments</comments>
		<pubDate>Wed, 04 May 2011 06:46:45 +0000</pubDate>
		<dc:creator>Amit Jain</dc:creator>
				<category><![CDATA[Javascript/Ajax/JQuery]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[querystring]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=3761</guid>
		<description><![CDATA[Hi Friends,

I was writing javascript to reload my page with different parameters. So I needed to create the queryString of those parameters but I didn&#8217;t want to create it of my own. I already knew about jQuery.serialize() which serializes the form and creates the queryString, but unfortunately I didn&#8217;t have form. So that gave me [...]]]></description>
			<content:encoded><![CDATA[<p>Hi Friends,<br />
<span id="more-3761"></span><br />
I was writing javascript to reload my page with different parameters. So I needed to create the queryString of those parameters but I didn&#8217;t want to create it of my own. I already knew about <a href="http://api.jquery.com/serialize/">jQuery.serialize()</a> which serializes the form and creates the queryString, but unfortunately I didn&#8217;t have form. So that gave me opportunity to learn about new <a href="http://api.jquery.com/jQuery.param/">jQuery.param()</a> which converts the JSON/Array into query string. Let us look at few examples below :</p>
<pre class="brush: jscript;">
var myParams = {country:&quot;US&quot;, customerId:&quot;1&quot;}
jQuery.param(myParams);

Output: &quot;country=US&amp;customerId=1&quot;
</pre>
<pre class="brush: jscript;">
var myParams = {name: &quot;Amit Jain&quot;,days:['Mon','Tue','Sat'] };
jQuery.param(myParams);

Output: &quot;name=Amit+Jain&amp;days%5B%5D=Mon&amp;days%5B%5D=Tue&amp;days%5B%5D=Sat&quot;
</pre>
<pre class="brush: jscript;">
var myParams = {name: &quot;Diana&quot;,address:{
  line1:&quot;232 Alder Dr.&quot;,
  line2:&quot;Alder City&quot;,
  state : &quot;Utah&quot;,
  country: &quot;US&quot;
}};
jQuery.param(myParams);

Output : &quot;name=Diana&amp;address%5Bline1%5D=232+Alder+Dr.&amp;address%5Bline2%5D=Alder+City&amp;address%5Bstate%5D=Utah&amp;address%5Bcountry%5D=US&quot;
</pre>
<p>Hope this helped!<br />
<!--more--><br />
Cheers!</p>
<p>~~Amit Jain~~<br />
amit@intelligrape.com</p>
<p>http://www.intelligrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2011/05/04/jquery-create-url-query-string-from-jsonarray/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>File Uploading using plupload plugin of jquery.</title>
		<link>http://www.intelligrape.com/blog/2011/02/14/file-uploading-using-plupload-plugin-of-jquery/</link>
		<comments>http://www.intelligrape.com/blog/2011/02/14/file-uploading-using-plupload-plugin-of-jquery/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 12:50:10 +0000</pubDate>
		<dc:creator>Anuj Aneja</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Javascript/Ajax/JQuery]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=2798</guid>
		<description><![CDATA[In my grails project i was having the requirement of having multiple file uploading, but in current implementation there was the problem of button being not loaded in Internet Explorer.For that i found plupload very cool to implement this. It has very cool feature of drag and drop and support for almost all browser. Actually [...]]]></description>
			<content:encoded><![CDATA[<p>In my grails project i was having the requirement of having multiple file uploading, but in current implementation there was the problem of button being not loaded in Internet Explorer.For that i found plupload very cool to implement this. It has very cool feature of drag and drop and support for almost all browser. Actually what it does is based on the browser, get the Runtime of the browser.For Documentation, js and css refer <a href="http://www.plupload.com/index.php">link</a></p>
<p>In gsp we need to include the js of pluplaod api as shown below:</p>
<pre class="brush: jscript;">
&lt;link rel=&quot;stylesheet&quot; href=&quot;${resource(dir: 'css/plupload/css', file: 'plupload.queue.css')}&quot; type=&quot;text/css&quot; media=&quot;screen&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;${resource(dir: 'css/plupload/css', file: 'jquery.ui.plupload.css')}&quot; type=&quot;text/css&quot; media=&quot;screen&quot;&gt;
&lt;g:set var=&quot;fileExtension&quot; value=&quot;${new FileExtension()}&quot;&gt;&lt;/g:set&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://www.google.com/jsapi&quot;&gt;&lt;/script&gt;
&lt;p:javascript src='jquery-1.3.2'/&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;${resource(dir: &quot;js/plupload&quot;, file: &quot;gears_init.js&quot;)}&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;${resource(dir: &quot;js/plupload&quot;, file: &quot;browserplus-min.js&quot;)}&quot;&gt;&lt;/script&gt;
&lt;!-- Load source versions of the plupload script files --&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;${resource(dir: &quot;js/plupload&quot;, file: &quot;plupload.js&quot;)}&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;${resource(dir: &quot;js/plupload&quot;, file: &quot;plupload.gears.js&quot;)}&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;${resource(dir: &quot;js/plupload&quot;, file: &quot;plupload.silverlight.js&quot;)}&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;${resource(dir: &quot;js/plupload&quot;, file: &quot;plupload.flash.js&quot;)}&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;${resource(dir: &quot;js/plupload&quot;, file: &quot;plupload.browserplus.js&quot;)}&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;${resource(dir: &quot;js/plupload&quot;, file: &quot;plupload.html5.js&quot;)}&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;${resource(dir: &quot;js/plupload&quot;, file: &quot;jquery.plupload.queue.js&quot;)}&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
    var button = '${buttonId}';
&lt;/script&gt;
</pre>
<p>Now we need to write script to load and bind the plupload plugin shown below:</p>
<pre class="brush: jscript;">
	&lt;script type=&quot;text/javascript&quot;&gt;
    var runtimesList;
    if (navigator.userAgent.indexOf(&quot;Firefox&quot;)!=-1){
        runtimesList='silverlight,browserplus,html4,gears,flash,html5';
    }else{
        runtimesList='html5,silverlight,browserplus,html4,gears,flash';
    }
    $(function() {
        var uploader = new plupload.Uploader({
            runtimes : runtimesList,
            browse_button : 'pickfiles',
            url : url,
            flash_swf_url : '${resource(dir: &quot;js/plupload&quot;, file: &quot;plupload.flash.swf&quot;)}',
            silverlight_xap_url : '${resource(dir: &quot;js/plupload&quot;, file: &quot;plupload.silverlight.xap&quot;)}',
            filters : [
                {title : &quot;Image files&quot;, extensions : &quot;gif,png&quot;},
                {title : &quot;Zip files&quot;, extensions : &quot;zip&quot;}
            ]
        });

        uploader.bind('Init', function(up, params) {
        });

        uploader.bind('FilesAdded', function(up, files) {
            $.each(files, function(i, file) {
                $('#filelist').append('&lt;div id=&quot;' + file.id + '&quot;&gt;&lt;span class=&quot;mcentd9d&quot; style=&quot;font-size:12px; color:green;&quot;&gt;File: ' + file.name + ' uploaded successfully!(' + plupload.formatSize(file.size) + ')&lt;b&gt;&lt;/b&gt;&lt;\/span&gt;' + '&lt;/div&gt;');
            });
        });

        uploader.bind('UploadFile', function(up, file) {

        });

        uploader.bind('UploadProgress', function(up, file) {
            $('#' + file.id + &quot; b&quot;).html(file.percent + &quot;%&quot;);
        });

        uploader.bind('QueueChanged', function(up) {
            $('#uploadfiles').click();
        });

        uploader.bind('FileUploaded', function(up) {

        });
        uploader.bind('Error', function(up) {
            alert('Error in uploading file');
        });

        $('#uploadfiles').click(function(e) {
            uploader.start();
            e.preventDefault();
        });
        uploader.init();
    });

&lt;/script&gt;
	&lt;div class=&quot;attachment&quot;&gt;
               &lt;div id=&quot;filelist&quot;&gt;&lt;/div&gt;
                      &lt;a href=&quot;#&quot; class=&quot;plupload_button plupload_add&quot; id=&quot;pickfiles&quot; style=&quot;position: relative; z-index: 0; &quot;&gt;Select File&lt;/a&gt;
                      &lt;input type='hidden' id=&quot;uploadfiles&quot;/&gt;
          &lt;/div&gt;
</pre>
<p>Now we need to handle the saving part of the file,for each file uploaded in Queue there is separate call to<br />
the action.It saves the file to the filePath specified.</p>
<pre class="brush: java;">
def saveAttachment={
      def files = request.getFileMap()
      def file=files.get(&quot;file&quot;)
      String fileName = file.getOriginalFilename()
      byte[] data=file.getBytes()
      File dir=new File(filePath)//some path...
      if(!dir.exists()){
         dir.mkdirs()
      }
      File actualFile=new File(filePath, fileName)
      actualFile.withOutputStream {out -&gt;
             out.write data
      }
}
</pre>
<p>Disclaimer: As in some cases you might want to can the upload of all the files as there is a different call to action of you can save there files in session, but session for this plupload is different from current user session so you will have to make your own session handling for that!!!</p>
<p>Note:The total length of files upload and and total uploaded differs in case IE and Firefox. The comments and any suggestions are welcomed.</p>
<p>Hope it help you guys! Cheer! <img src='http://www.intelligrape.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Anuj Aneja</p>
<p>http://www.Intelligrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2011/02/14/file-uploading-using-plupload-plugin-of-jquery/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>JQuery script to put focus on first field of any page</title>
		<link>http://www.intelligrape.com/blog/2011/01/13/jquery-script-to-put-focus-on-first-field-of-any-page/</link>
		<comments>http://www.intelligrape.com/blog/2011/01/13/jquery-script-to-put-focus-on-first-field-of-any-page/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 15:03:56 +0000</pubDate>
		<dc:creator>Vishal Sahu</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[HTML-UI-CSS]]></category>
		<category><![CDATA[Javascript/Ajax/JQuery]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jQuery focus]]></category>
		<category><![CDATA[jQuery Script]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=2546</guid>
		<description><![CDATA[Hi,
In my recent grails project, i needed to put focus on the first field of any page whenever the page loads. The requirement is such that if the page contains errors then the focus should be on the first input field which has errors.
I searched a lot and with the help of my colleague we [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>In my recent grails project, i needed to put focus on the first field of any page whenever the page loads. The requirement is such that if the page contains errors then the focus should be on the first input field which has errors.</p>
<p>I searched a lot and with the help of my colleague we came out with a simple JQuery script to put focus on the first input field on any page  whenever the page loads.<br />
<br />
The script i used is:-</p>
<pre>

   if (jQuery('.errors').size() &gt; 0) {
       jQuery('input.errors:first').focus();
       jQuery('.errors input:visible:first').focus();
     }
   else {
      jQuery('input:text:visible:first').focus();
    }
</pre>
<p>I put it in the layout and it works for every gsp which has that layout.</p>
<p></p>
<p>It worked for me.<br />
Hope it Helps.<br />
<br />
Vishal Sahu<br />
vishal@intelligrape.com<br />
<a href="http://www.intelligrape.com">www.intelligrape.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2011/01/13/jquery-script-to-put-focus-on-first-field-of-any-page/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Jquery : map and grep functions</title>
		<link>http://www.intelligrape.com/blog/2010/11/15/jquery-map-and-grep-methods/</link>
		<comments>http://www.intelligrape.com/blog/2010/11/15/jquery-map-and-grep-methods/#comments</comments>
		<pubDate>Sun, 14 Nov 2010 19:32:25 +0000</pubDate>
		<dc:creator>Amit Jain</dc:creator>
				<category><![CDATA[Javascript/Ajax/JQuery]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[map]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=2117</guid>
		<description><![CDATA[Hi friends,
I was going through some utility funcitons being provided by jQuery. Found few methods like grep, map very userful that saves me from writing loops. I could relate them with grep, collect respectively as provided by Groovy, thought would share with you.
I will be taking examples with JSON objects say Student.
grep()

var students = [ [...]]]></description>
			<content:encoded><![CDATA[<p>Hi friends,</p>
<p>I was going through some utility funcitons being provided by jQuery. Found few methods like grep, map very userful that saves me from writing loops. I could relate them with grep, collect respectively as provided by Groovy, thought would share with you.</p>
<p>I will be taking examples with JSON objects say Student.<br />
<a href="  http://api.jquery.com/jQuery.grep/">grep()</a></p>
<pre class="brush: jscript;">
var students = [ {'id':1, 'name':'amit'},{'id':2, 'name':'ankit'}];
jQuery.grep(students,function(student){ return student.id&gt;1});

//Output :  [{'id':2, 'name':'ankit'}]

jQuery.grep(students,function(student){ return student.id&gt;1}, true) // invert the results

//Output : [ {'id':1, 'name':'amit'}]
</pre>
<p><a href="http://api.jquery.com/jQuery.map/">map() </a></p>
<pre class="brush: jscript;">
 var students = [ {'id':1, 'name':'amit'},{'id':2, 'name':'ankit'}];
jQuery.map(students,function(student){ return student.name=student.name.toUpperCase()});

//Output : [&quot;AMIT&quot;, &quot;ANKIT&quot;]
//Updated students list :  [ {'id':1, 'name':'AMIT'},{'id':2, 'name':'ANKIT'}];

jQuery.map(students,function(student){ return student.greetings=&quot;HELLO &quot; + student.name});

//Output : [&quot;HELLO AMIT&quot;, &quot;HELLO ANKIT&quot;]
//Updated students list : [ {'id':1, 'name':'AMIT', 'greetings' : 'HELLO AMIT'},{'id':2, 'name':'ANKIT', 'greetings' : 'HELLO ANKIT'}]
</pre>
<p>Hope this helped.</p>
<p>~~Amit Jain~~<br />
amit@intelligrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2010/11/15/jquery-map-and-grep-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asynchronous behavior of AJAX</title>
		<link>http://www.intelligrape.com/blog/2010/09/14/asynchronous-behavior-of-ajax/</link>
		<comments>http://www.intelligrape.com/blog/2010/09/14/asynchronous-behavior-of-ajax/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 15:36:27 +0000</pubDate>
		<dc:creator>Bhagwat Kumar</dc:creator>
				<category><![CDATA[Javascript/Ajax/JQuery]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ajaxSettings.aync]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[synchronous]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=1688</guid>
		<description><![CDATA[Ajax (shorthand for Asynchronous JavaScript and XML) is used to retrieve data from the server asynchronously without interfering with the display and behavior of the existing page. Forgetting this asynchronous behavior will produce incorrect result if it depends on the response from Ajax call.
Lets take an example(I am using JQuery to illustrate the example). Here [...]]]></description>
			<content:encoded><![CDATA[<p>Ajax (shorthand for Asynchronous JavaScript and XML) is used to retrieve data from the server asynchronously without interfering with the display and behavior of the existing page. Forgetting this asynchronous behavior will produce incorrect result if it depends on the response from Ajax call.</p>
<p>Lets take an example(I am using <a href="http://api.jquery.com/category/ajax/" target="_blank">JQuery</a> to illustrate the example). Here is a JavaScript function to perform server side check of the form. Depending on the response of Ajax call the function either submits the form or does nothing.</p>
<div class="code">

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> submitForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> isFormValid<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> dataToBeSent<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$.<span style="color: #006600;">get</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> dataToBeSent<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		isFormValid<span style="color: #339933;">=</span>result<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>isFormValid<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</div>
<p>The statement <code> $('form').submit()</code> will never be called irrespective of the <code>result</code> (AJAX call response). After executing <code>$.get</code> statement it will execute the next statement  <code>if(isFormValid) </code>without waiting for the statement <code>isFormValid=result</code> inside the callback function to be executed.</p>
<p>There exist a dirty solution for the problem : using JavaScript sleep API. But how long you are going to halt the execution of JavaScript code. You are back to the same problem of getting the incorrect behavior.</p>
<p>One good solution is to make the $.get call synchronous by making changes to the global AJAX configuration like :</p>
<div class="code">

<div class="wp_syntax"><div class="code"><pre class="javascript">$.<span style="color: #006600;">ajaxSettings</span>.<span style="color: #006600;">async</span><span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span></pre></div></div>

</div>
<p>or using calls like :</p>
<div class="code">

<div class="wp_syntax"><div class="code"><pre class="javascript">$.<span style="color: #006600;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span> url<span style="color: #339933;">:</span> url<span style="color: #339933;">,</span> data<span style="color: #339933;">:</span> dataToBeSent<span style="color: #339933;">,</span> success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		isFormValid<span style="color: #339933;">=</span>result<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</div>
<p>Now the<code> if(isFormValid) </code>statement will be executed only after the<code> $.ajax </code>statement has completed its execution. However this approach has its own drawback. Obvious one is the execution of JavaScript halts until it receives the response.</p>
<p>However the better solution  is to execute<code> $('form').submit()</code> inside the callback function like :</p>
<div class="code">

<div class="wp_syntax"><div class="code"><pre class="javascript">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'submitButton'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> isFormValid<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> dataToBeSent<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$.<span style="color: #006600;">get</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> dataToBeSent<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		isFormValid<span style="color: #339933;">=</span>result<span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>isFormValid<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">// Needless if the button is not a submit button</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

</div>
<p><code>return false</code> statement at the end of the function prevents the form from being submitted. Now the form submission code will be executed only after the response to<code> $.get</code> statement is true.</p>
<p>There exist JQuery plugins (e.g. JQuery validation plugin) for doing form validation in a better way where you get support for server side validation also. But the case discussed above was to make you understand the asynchronous behavior of AJAX calls.</p>
<p>Hope this helps you while using Ajax.  <img src='http://www.intelligrape.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Cheers,<br />
~~Bhagwat Kumar~~<br />
bhagwat(at)intelligrape(dot)com</p>
<p>http://www.intelligrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2010/09/14/asynchronous-behavior-of-ajax/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery: Floating message box which disappears in few seconds</title>
		<link>http://www.intelligrape.com/blog/2010/09/14/jquery-floating-message-box-which-disappears-in-few-seconds/</link>
		<comments>http://www.intelligrape.com/blog/2010/09/14/jquery-floating-message-box-which-disappears-in-few-seconds/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 19:01:24 +0000</pubDate>
		<dc:creator>Amit Jain</dc:creator>
				<category><![CDATA[Javascript/Ajax/JQuery]]></category>
		<category><![CDATA[floating message]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[message box]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=1636</guid>
		<description><![CDATA[Hi Friends,
Recently in one of the project I was working on, had a long web page and updates used to happen only through ajax calls that means no page refresh. The status messages used to appear on the top of the page, the user had no way but to scroll up to see the status [...]]]></description>
			<content:encoded><![CDATA[<p>Hi Friends,</p>
<p>Recently in one of the project I was working on, had a long web page and updates used to happen only through ajax calls that means no page refresh. The status messages used to appear on the top of the page, the user had no way but to scroll up to see the status message. There we thought of using floating message that always appears on the top and floats as and when page is scrolled and also disappears itself after specified amount of time. I found one<a href="http://roshanbh.com.np/2008/07/top-floating-message-box-using-jquery.html"> blog</a> by Roshan that helped a lot, which I tweaked a little as given below.</p>
<p>CSS code to be added :</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="css"><span style="color: #cc00cc;">#message_box</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #66cc66;">:</span> <span style="color: #993333;">absolute</span><span style="color: #66cc66;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #66cc66;">:</span> <span style="color: #933;">0</span><span style="color: #66cc66;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #66cc66;">:</span> <span style="color: #933;">0</span><span style="color: #66cc66;">;</span>
    <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #66cc66;">:</span> <span style="color: #933;">1000</span><span style="color: #66cc66;">;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #66cc66;">:</span> <span style="color: #cc00cc;">#ffc</span><span style="color: #66cc66;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #66cc66;">:</span> <span style="color: #933;">5px</span><span style="color: #66cc66;">;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #66cc66;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#CCCCCC</span><span style="color: #66cc66;">;</span>
    <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #66cc66;">:</span> <span style="color: #993333;">center</span><span style="color: #66cc66;">;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #66cc66;">:</span> <span style="color: #993333;">bold</span><span style="color: #66cc66;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #66cc66;">:</span> <span style="color: #933;"><span style="color: #933;">99</span>%</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

</blockquote>
<p>Html code containing message : :-</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;message_box&quot;</span><span style="color: #339933;">&gt;</span>Your message goes here<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Call setupMessageBox() when message is available.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #003366; font-weight: bold;">var</span> updateTimer <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">function</span> setupMessageBox<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    showMessage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//displays message on page load</span>
    jQuery<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">scroll</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       showMessage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
    clearTimeout<span style="color: #009900;">&#40;</span>updateTimer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    activateTimer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> activateTimer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    updateTimer <span style="color: #339933;">=</span> setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'jQuery(&quot;#message_box&quot;).remove()'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> showMessage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#message_box'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>top<span style="color: #339933;">:</span>jQuery<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">scrollTop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;px&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>queue<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>duration<span style="color: #339933;">:</span><span style="color: #CC0000;">350</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Hope this helped!</p>
<p>Cheers,<br />
~~Amit Jain~~<br />
amit@intelligrape.com</p>
<p>http://www.intelligrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2010/09/14/jquery-floating-message-box-which-disappears-in-few-seconds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Alert Message without using traditional javascript alert-box.</title>
		<link>http://www.intelligrape.com/blog/2010/06/14/jquery-alert-message-without-using-traditional-javascript-alert-box/</link>
		<comments>http://www.intelligrape.com/blog/2010/06/14/jquery-alert-message-without-using-traditional-javascript-alert-box/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 16:50:30 +0000</pubDate>
		<dc:creator>Salil</dc:creator>
				<category><![CDATA[HTML-UI-CSS]]></category>
		<category><![CDATA[Javascript/Ajax/JQuery]]></category>
		<category><![CDATA[custom alert messages]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=1093</guid>
		<description><![CDATA[This post might help you if you want to display alert messages without using tradition javascript (irritating) alert.
To achieve this you need jQuery for your frontend UI.
Below is the javascript method (code snapshot) which displays your message for 5 seconds. And then fades out automatically.


function displayAlertMessage&#40;message&#41; &#123;
var timeOut = 5
jQuery&#40;'#messageBox'&#41;.text&#40;message&#41;.fadeIn&#40;&#41;
jQuery&#40;'#messageBox'&#41;.css&#40;&#34;display&#34;, &#34;block&#34;&#41;
setTimeout&#40;function&#40;&#41; &#123;
jQuery&#40;'#messageBox'&#41;.fadeOut&#40;&#41;
jQuery&#40;'#messageBox'&#41;.css&#40;&#34;display&#34;, &#34;none&#34;&#41;
&#125;, timeOut * [...]]]></description>
			<content:encoded><![CDATA[<p>This post might help you if you want to display alert messages without using tradition javascript (irritating) alert.<br />
To achieve this you need jQuery for your frontend UI.</p>
<p>Below is the javascript method (code snapshot) which displays your message for 5 seconds. And then fades out automatically.</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> displayAlertMessage<span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> timeOut <span style="color: #339933;">=</span> <span style="color: #CC0000;">5</span>
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#messageBox'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">text</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#messageBox'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;display&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;block&quot;</span><span style="color: #009900;">&#41;</span>
setTimeout<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#messageBox'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#messageBox'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;display&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;none&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> timeOut <span style="color: #339933;">*</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</blockquote>
<p>messageBox is id of your div tag where you want to display the Alert Message.<br />
timeOut is number of seconds you want to hold message on screen.<br />
That&#8217;s it. So simple and quite comfortable from a user&#8217;s perspective Isn&#8217;t it? <img src='http://www.intelligrape.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Cheers!!<br />
Salil Kalia</p>
<p>﻿</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2010/06/14/jquery-alert-message-without-using-traditional-javascript-alert-box/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>JQuery: Send JSON Objects with an ajax request</title>
		<link>http://www.intelligrape.com/blog/2010/06/11/jquery-send-json-object-with-an-ajax-request/</link>
		<comments>http://www.intelligrape.com/blog/2010/06/11/jquery-send-json-object-with-an-ajax-request/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 10:30:09 +0000</pubDate>
		<dc:creator>Amit Jain</dc:creator>
				<category><![CDATA[Javascript/Ajax/JQuery]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[JSON]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=1039</guid>
		<description><![CDATA[Hi Friends,
Lets discuss today about sending JSON objects with ajax request using JQuery. We have number of functions in jQuery to kick-off an ajax request. But for sending JSON objects along with the request, I chose jQuer.ajax(). It takes various parameters url, type, data, dataType, beforeSend etc. Its API can be found here.
Lets look at [...]]]></description>
			<content:encoded><![CDATA[<p>Hi Friends,</p>
<p>Lets discuss today about sending JSON objects with ajax request using JQuery. We have number of functions in jQuery to kick-off an ajax request. But for sending JSON objects along with the request, I chose jQuer.ajax(). It takes various parameters url, type, data, dataType, beforeSend etc. Its API can be found <a href="http://api.jquery.com/jQuery.ajax/">here</a>.</p>
<p>Lets look at example given below:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript">jQuery.<span style="color: #006600;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
          url<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;</span>Url of the action<span style="color: #339933;">&gt;,</span>
          type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
          data<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;amit&quot;</span><span style="color: #339933;">,</span> id<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
          dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span>
          beforeSend<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&amp;&amp;</span> x.<span style="color: #006600;">overrideMimeType</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
              x.<span style="color: #006600;">overrideMimeType</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;application/j-son;charset=UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
          <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
          success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 	     <span style="color: #006600; font-style: italic;">//Write your code here</span>
          <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The above example works for simple JSON object. Now lets see how we can send JSON objects list as given below:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">var</span> jsonObjects <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span>id<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;amit&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>id<span style="color: #339933;">:</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;ankit&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>id<span style="color: #339933;">:</span><span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> <span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;atin&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>id<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;puneet&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
jQuery.<span style="color: #006600;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
          url<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;</span>Url of the action<span style="color: #339933;">&gt;,</span>
          type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
          data<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>students<span style="color: #339933;">:</span> JSON.<span style="color: #006600;">stringify</span><span style="color: #009900;">&#40;</span>jsonObjects<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
          dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span>
          beforeSend<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&amp;&amp;</span> x.<span style="color: #006600;">overrideMimeType</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
              x.<span style="color: #006600;">overrideMimeType</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;application/j-son;charset=UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
          <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
          success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 	     <span style="color: #006600; font-style: italic;">//Write your code here</span>
          <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you notice, for sending my json objects it has not been written directly as data: jsonObjects. As it expects the JSON object passed to it written as key value pair. So we made students the key. And since we have json objects stored in a variable, we need to expand the json objects list using stringify(), otherwise it would be sent as a java script object.</p>
<p>Now on the server we can parse the JSON object, and use it as the list of objects of type map. For example</p>

<div class="wp_syntax"><div class="code"><pre class="groovy"><span style="color: #808080; font-style: italic;">//this code is written in grails </span>
<span style="color: #a1a100;">import grails.converters.JSON;</span>
List<span style="color: #66cc66;">&lt;</span>JSON<span style="color: #66cc66;">&gt;</span> students <span style="color: #66cc66;">=</span> JSON.<span style="color: #006600;">parse</span><span style="color: #66cc66;">&#40;</span>params.<span style="color: #006600;">students</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">//students in request params is parsed to json objects and stored in the List</span>
<span style="color: #993399;">println</span> <span style="color: #ff0000;">&quot;Student id: &quot;</span> + students<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">studentId</span>    <span style="color: #808080; font-style: italic;">//first element of the students list is accessed as a map holding a key studentId</span></pre></div></div>

<p>Hope this helpled!</p>
<p>~~Amit Jain~~<br />
amit@intelligrape.com</p>
<p>http://www.IntelliGrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2010/06/11/jquery-send-json-object-with-an-ajax-request/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>jQuery : Chaining of your custom function calls</title>
		<link>http://www.intelligrape.com/blog/2010/06/04/jquery-chaining-of-your-custom-function-calls/</link>
		<comments>http://www.intelligrape.com/blog/2010/06/04/jquery-chaining-of-your-custom-function-calls/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 10:57:05 +0000</pubDate>
		<dc:creator>Amit Jain</dc:creator>
				<category><![CDATA[Javascript/Ajax/JQuery]]></category>
		<category><![CDATA[custom functions]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery function chaining]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=797</guid>
		<description><![CDATA[Hi Friends,
I always used to think how jQuery provides the chaining mechanism, must be something really complex so never cared to find it out. Though there was a desire to to use the same concept in my own custom javascript functions. Recently I realised how easy it is, so thought would share with you with [...]]]></description>
			<content:encoded><![CDATA[<p>Hi Friends,</p>
<p>I always used to think how jQuery provides the chaining mechanism, must be something really complex so never cared to find it out. Though there was a desire to to use the same concept in my own custom javascript functions. Recently I realised how easy it is, so thought would share with you with the help of an example.</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="javascript">jQuery.<span style="color: #006600;">fn</span>.<span style="color: #006600;">getStudents</span><span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>count<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  <span style="color: #006600; font-style: italic;">//count is the parameter name and getStudents is the function name.</span>
<span style="color: #006600; font-style: italic;">//write your code here</span>
...
<span style="color: #000066; font-weight: bold;">return</span> myObject  <span style="color: #006600; font-style: italic;">//return is optional</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</blockquote>
<p>Now we can access the above function using dot operator on jQuery Object.</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="javascript">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#myListId&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">getStudents</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</blockquote>
<p>Please make a note the object returned by the previous function is made available to the chained functions as &#8220;this&#8221; object, that is one of the reason chaining became so useful. So in the above function getStudents(), &#8220;this&#8221; object would refer to the object returned by jQuery(&#8220;#myListId&#8221;). </p>
<p>Remember, to have chaining upto multiple levels, it becomes the obligation for the calling function to must return an object/value to the chained function being called on it.</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="javascript">jQuery.<span style="color: #006600;">fn</span>.<span style="color: #006600;">highlightNames</span><span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">//write your code here</span>
jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">find</span><span style="color: #009900;">&#40;</span>...<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</blockquote>
<p>Now we can access the above function i.e highlightNames() using dot operator even on another function.</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="javascript">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#myListId&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">getStudents</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">highlightNames</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</blockquote>
<p>Here I didn&#8217;t have to passes the students object to highlightNames, as it was available as a &#8220;this&#8221; object.</p>
<p>Hope it helped!</p>
<p>~~Amit Jain~~<br />
amit@intelligrape.com</p>
<p>http://www.intelligrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2010/06/04/jquery-chaining-of-your-custom-function-calls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monitoring  ajax call response</title>
		<link>http://www.intelligrape.com/blog/2010/03/04/monitoring-ajax-call-response/</link>
		<comments>http://www.intelligrape.com/blog/2010/03/04/monitoring-ajax-call-response/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 06:31:13 +0000</pubDate>
		<dc:creator>Bhagwat Kumar</dc:creator>
				<category><![CDATA[Javascript/Ajax/JQuery]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=424</guid>
		<description><![CDATA[Recently I have faced a problem of monitoring all the ajax calls. Based on the response from server I have to perform some task depending on the contents of response. If the html response contains some text input field, the first text input field should be automatically focused otherwise leave the response as it is. [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have faced a problem of monitoring all the ajax calls. Based on the response from server I have to perform some task depending on the contents of response. If the html response contains some text input field, the first text input field should be automatically focused otherwise leave the response as it is. </p>
<p>Here is the javascript code :</p>
<blockquote>
<div class="code">

<div class="wp_syntax"><div class="code"><pre>&lt;span id=&quot;ajax_spinner&quot; style=&quot;display:none<SEMI>&quot;&gt;&lt;/span&gt;</pre></div></div>

</div>
</blockquote>
<blockquote>
<div class="code">

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
            jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#ajax_spinner&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">ajaxComplete</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> xhr<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> jQuery.<span style="color: #006600;">httpData</span><span style="color: #009900;">&#40;</span>xhr<span style="color: #339933;">,</span>options.<span style="color: #006600;">dataType</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">/* 
                 Now data contains the responseText if the response type
		 is text/html or text/palin otherwise it is undefined.
                 */</span>
                <span style="color: #003366; font-weight: bold;">var</span> inputFieldIndex<span style="color: #339933;">=</span><span style="color: #CC0000;">-1</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
			<span style="color: #009966; font-style: italic;">/* try-catch because data may be undefined as mentioned above. */</span>
			inputFieldIndex<span style="color: #339933;">=</span>data.<span style="color: #006600;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;input&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>err<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>inputFieldIndex<span style="color: #339933;">&gt;</span><span style="color: #CC0000;">-1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>	
                   <span style="color: #009966; font-style: italic;">/* response contains input tag */</span>
                    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input:text:visible[disabled=false]:first'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
          <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

</div>
</blockquote>
<p>The above trick worked for me and hope it works for you guys too.</p>
<p>Helpful links :-<br />
<a class="alignleft" href="http://api.jquery.com/ajaxComplete/" target="_blank"> http://api.jquery.com/ajaxComplete/</a></p>
<p> ~~~~Bhagwat Kumar~~~<br />
bhagwat@intelligrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2010/03/04/monitoring-ajax-call-response/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

