<?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>JackKozik.com &#187; Web Programming</title> <atom:link href="http://jackkozik.com/tag/web-programming/feed" rel="self" type="application/rss+xml" /><link>http://jackkozik.com</link> <description>Web Programming, Home Networking and Personal Travel</description> <lastBuildDate>Mon, 04 Sep 2023 14:26:56 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.9.2</generator> <item><title>$.ajax logging using Ajax Global Events. Re-factoring Single Page Web Application</title><link>http://jackkozik.com/ajax-logging-using-ajax-global-events-re-factoring-single-page-web-application/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ajax-logging-using-ajax-global-events-re-factoring-single-page-web-application</link> <comments>http://jackkozik.com/ajax-logging-using-ajax-global-events-re-factoring-single-page-web-application/#comments</comments> <pubDate>Tue, 03 Dec 2013 04:14:42 +0000</pubDate> <dc:creator><![CDATA[Jack Kozik]]></dc:creator> <category><![CDATA[Web Programming]]></category> <category><![CDATA[$.ajax]]></category> <category><![CDATA[Jquery]]></category> <category><![CDATA[logging]]></category><guid isPermaLink="false">http://jackkozik.com/?p=4670</guid> <description><![CDATA[<p>Background on $.ajax logging using Ajax Global Events:  So I&#8217;ve moved from jQuery 1.4 to 1.9. I have some time to refactor my code to take advantage of some of the new features of 1.9 and to get ready for 1.10; the next jQuery release removes some of the deprecated methods. For this round of coding, [&#8230;]</p><p>The post <a rel="nofollow" href="http://jackkozik.com/ajax-logging-using-ajax-global-events-re-factoring-single-page-web-application/">$.ajax logging using Ajax Global Events. Re-factoring Single Page Web Application</a> appeared first on <a rel="nofollow" href="http://jackkozik.com">JackKozik.com</a>.</p> ]]></description> <content:encoded><![CDATA[<p>Background on $.ajax logging using Ajax Global Events:  So I&#8217;ve moved from jQuery 1.4 to 1.9. I have some time to refactor my code to take advantage of some of the new features of 1.9 and to get ready for 1.10; the next jQuery release removes some of the deprecated methods.</p><p>For this round of coding, I am focusing on the <code>$.ajax()</code> method. In my present design, my single page web application makes REST calls for many of the UI menu items. For example, a click on the FILE-&gt;LOAD menu item triggers a function call to code that retrieves a file from my server. The basic pattern is like this:</p><pre class="brush: jscript; title: ; notranslate">
// Start spinner
// start logging timer
$.ajax({&quot;url&quot;:RestURI,
 &quot;type&quot;:&quot;GET&quot;,
 &quot;dataType&quot;:&quot;json&quot;,
 success: function(data) {
 // Do success stuff (parse, format and display)
 // stop logging timer, do logging
 // stop spinnger
 }, /* end success: */

 error: function (req, stat, err) {
 // Do error stuff
 // stop logging timer, do logging
 // stop spinner
 } /* end error: */
});
</pre><p>I have more than 7 code blocks that follow this pattern. Since<a href="view-source:http://api.jquery.com/jQuery.ajax/#jqXHR"> the success/error/complete callback functions have been deprecated </a>and I need to touch the code anyways, I thought I&#8217;d use the newish<a href="http://api.jquery.com/category/ajax/global-ajax-event-handlers/"> <code>$.ajax()</code> global events handlers</a>  to clean up my code. The event handlers seem to be a useful place to put common pieces of code that really shouldn&#8217;t have been so liberally cut-and-pasted when I wrote the original code.</p><p><a href="http://jackkozik.com/wp-content/uploads/2013/12/jQueryIcon120213.jpg"><img class="alignright size-full wp-image-4678" alt="jQueryIcon120213" src="http://jackkozik.com/wp-content/uploads/2013/12/jQueryIcon120213.jpg" width="184" height="168" /></a>For each of my ajax code blocks, I put a generous amount of logging in. Maybe this logging should only be needed when writing/debugging the code, but for me, since I spend so little dedicated time on this application, I wanted to keep verbose logging on always to make it real easy for me to debug.</p><h4>$.ajax logging using Ajax Global Events</h4><p>The following new block of code is doing my <code>$.ajax</code> logging using Ajax Global Events.</p><pre class="brush: jscript; title: ; notranslate">
$(document).ajaxSend(function(evt, xhr, settings) {
 console.log(settings.type+&quot; &quot;+settings.url+&quot; Sent&quot;);
 start = new Date().getTime();
 // Other logging
});
$(document).ajaxSuccess(function(evt, xhr, settings) {
 console.log(settings.type+&quot; &quot;+settings.url+&quot; Success&quot;);
 // Other logging
});
$(document).ajaxError(function(evt, xhr, settings, exc) {
 console.log( settings.type+&quot; &quot;+settings.url+&quot; Failed. &quot;
 +xhr.status+&quot;-&quot;+xhr.statusText);
 // Other logging
});
$(document).ajaxComplete(function(evt, xhr, settings) {
 console.log(settings.type+&quot; &quot;+settings.url+&quot; Complete&quot;);
 end = new Date().getTime();
 diff = end - start;
 // Other logging
});
</pre><p>As you can see, the ajaxSend/ajaxSuccess/ajaxError/ajaxComplete events are fired in sequence at the <code>$.ajax()</code> function executes and after the  <code>.done()</code>, <code>.fail()</code> and <code>.compete()</code> callbacks are executed.</p><p>The &#8220;Other logging&#8221; comment represents 2 or 3 lines of code where I put logging information into a user visible menu item (REPORTS-&gt;LOG) where I can see even more details without having to open the console window. For me, this effort is a nice clean out some of the logging stuff, to make the application logic a little more visible;  this clears up a bunch of clutter for me.</p><h4>New-ish .done/.fail/.always Callbacks</h4><p>Therefore, my $.ajax() code blocks are straighten out to follow the new done/fail/always callbacks. Here&#8217;s an example new $.ajax() code block:</p><pre class="brush: jscript; title: ; notranslate">
// Start spinner
$.ajax({url:RestURI,
 type:&quot;GET&quot;,
 dataType:&quot;json&quot;})
 .done( function(data, textStatus, jqXHR) {
 // Do success stuff
 }) /* end done: */

 .fail( function (jqXHR, textStatus, err) {
 // Do error stuff
 }) /* end fail */

 .always( function() {
 // stop spinner
 }); /* End always */
</pre><p>Some things to note: I still put the start/stop spinner function calls inline. I may move this to the global even handlers, but not yet.</p><h4>Deferred Objects</h4><p>Also, the done/fail/always call backs follow the new<a href="http://api.jquery.com/category/deferred-object/"> Deferred Object</a> model. This will then let me setup some promise objects to let me address some of the async race conditions I have in my application.</p><p>For example, I have a case where I can run FILE-&gt;SAVE and then run REPORT-&gt;General and the report will produce results before the save was completed. I know how to fix this, but I was looking to use my new ajax code blocks architecture to get some practice with promise objects instead&#8230; for next time.</p><p>The post <a rel="nofollow" href="http://jackkozik.com/ajax-logging-using-ajax-global-events-re-factoring-single-page-web-application/">$.ajax logging using Ajax Global Events. Re-factoring Single Page Web Application</a> appeared first on <a rel="nofollow" href="http://jackkozik.com">JackKozik.com</a>.</p> ]]></content:encoded> <wfw:commentRss>http://jackkozik.com/ajax-logging-using-ajax-global-events-re-factoring-single-page-web-application/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Updating to jQuery 1.9</title><link>http://jackkozik.com/updating-my-website-to-jquery-1-9/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=updating-my-website-to-jquery-1-9</link> <comments>http://jackkozik.com/updating-my-website-to-jquery-1-9/#comments</comments> <pubDate>Fri, 09 Aug 2013 17:30:56 +0000</pubDate> <dc:creator><![CDATA[Jack Kozik]]></dc:creator> <category><![CDATA[Web Programming]]></category> <category><![CDATA[1.9 Upgrade]]></category> <category><![CDATA[2013]]></category> <category><![CDATA[Jquery]]></category><guid isPermaLink="false">http://jackkozik.com/?p=4579</guid> <description><![CDATA[<p>Background on why I was Updating to jQuery 1.9:  For a number of reasons, I needed to update my website to a newer version of jQuery, jQuery 1.9. My site, designed in 2010 was started on v1.4 and had last been updated to 1.7 in 2011. I knew I had several out-of-date methods and expected [&#8230;]</p><p>The post <a rel="nofollow" href="http://jackkozik.com/updating-my-website-to-jquery-1-9/">Updating to jQuery 1.9</a> appeared first on <a rel="nofollow" href="http://jackkozik.com">JackKozik.com</a>.</p> ]]></description> <content:encoded><![CDATA[<p>Background on why I was Updating to jQuery 1.9:  For a number of reasons, I needed to update my website to a newer version of jQuery, jQuery 1.9. My site, designed in 2010 was started on v1.4 and had last been updated to 1.7 in 2011. I knew I had several out-of-date methods and expected to some debugging and troubleshooting. Well, in the end, it took me 6 hours spread over two days. It wasn&#8217;t really that bad, but since I don&#8217;t upgrade jQuery everyday, I had a little re-learning to go through.</p><p>For starters, I knew that v1.9 had deprecated many of its old methods. In fact, I learned from the <a href="http://jquery.com/upgrade-guide/1.9/">upgrade web page</a>, , that v1.9 comes with a special <a href="https://github.com/jquery/jquery-migrate">migration plug-in</a>. I was pleased to see this and used this to address most all of my updating challenages.</p><p>For example, $.browser() method was deprecated. The migrate script reported this to me in the Chrome console, as follows:</p><p>Chrome console:</p><p><a href="http://jackkozik.com/updating-my-website-to-jquery-1-9/jqmigratebrowser080813/" rel="attachment wp-att-4580"><img class="alignleft size-full wp-image-4580" title="JQMIGRATE:  jQuery.browser is deprecated" alt="" src="http://jackkozik.com/wp-content/uploads/2013/08/JQMIGRATEbrowser080813.png" width="734" height="46" /></a></p><p>With a little digging, I was able to find that I was using an old version of <a href="https://github.com/malsup/blockui">blockUI</a>. When I changed to the new version the warning message went away.</p><p>I also got the following warning messages related to type changing and the change to the <a href="http://api.jquery.com/andSelf/">andSelf()</a> method:</p><p>Chrome console:</p><p><a href="http://jackkozik.com/wp-content/uploads/2013/08/JQMIGRATEtmpl080813.png"><img class="alignleft size-full wp-image-4581" title="JQMIGRATE: jQuery.fn.andSelf() replaced by addBack()" alt="" src="http://jackkozik.com/wp-content/uploads/2013/08/JQMIGRATEtmpl080813.png" width="719" height="35" /></a></p><p>Again, it took a lot of digging, but I was able to isolate the problem to my <a href="https://github.com/KanbanSolutions/jquery-tmpl">tmpl.js</a> script. I was using a really old version. I think with a little more skill on my part, I would better be able to use stack backtraces or some other Chrome tool to find these quicker, but this problem was hard for me to find.</p><p>Since I was also using an old version of jQuery-UI, I stumbled upon a couple of breakages triggered by curCSS:</p><p>Chrome console:</p><p><a href="http://jackkozik.com/wp-content/uploads/2013/08/ErrorcurCSS080813.png"><img class="alignleft size-full wp-image-4582" title="Uncaught TypeError: ... has no method curCSS" alt="" src="http://jackkozik.com/wp-content/uploads/2013/08/ErrorcurCSS080813.png" width="935" height="19" /></a></p><p>For some reason, also, the dialog() method wouldn&#8217;t display text in the &#8220;OK&#8221; button and it would always popup at 0.0 (upper left), so I upgraded to<a href="http://api.jqueryui.com/1.9/"> jQuery-ui v1.9.2</a>.</p><p>One last thing for Updating to jQuery 1.9. I had to <a href="http://jquery.com/upgrade-guide/1.9/#live-removed">change all of my .live() events to .on()</a>. The migration guide clearly covered this.</p><p>Here&#8217;s an example from my website:</p><pre class="brush: jscript; title: ; notranslate">
//$('#journal input').live('keydown', function(evt) {
$(document).on('keydown','#journal input', function(evt) {
</pre><p>This was easy to do; I had to do it in 6 different place, and it worked the first time.</p><p>Updating to jQuery 1.9 was a little more painful than I would like, but feels good to get caught up.</p><p>Ok, now that I&#8217;ve converted to jQuery v1.9, I can try out some of the new things.</p><p>The post <a rel="nofollow" href="http://jackkozik.com/updating-my-website-to-jquery-1-9/">Updating to jQuery 1.9</a> appeared first on <a rel="nofollow" href="http://jackkozik.com">JackKozik.com</a>.</p> ]]></content:encoded> <wfw:commentRss>http://jackkozik.com/updating-my-website-to-jquery-1-9/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>