<?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>uxebu » blog &#187; ajax</title>
	<atom:link href="http://uxebu.com/tag/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://uxebu.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 19 Jan 2012 14:53:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>EventNinja: A mobile must-have Widget for the mobile2.0</title>
		<link>http://uxebu.com/blog/2009/06/16/eventninja-a-mobile-must-have-widget-for-the-mobile20/</link>
		<comments>http://uxebu.com/blog/2009/06/16/eventninja-a-mobile-must-have-widget-for-the-mobile20/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 08:31:43 +0000</pubDate>
		<dc:creator>wolfram</dc:creator>
				<category><![CDATA[business]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[uxebu]]></category>
		<category><![CDATA[w3c widgets]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mobile2.0]]></category>
		<category><![CDATA[phonegap]]></category>
		<category><![CDATA[w3c]]></category>

		<guid isPermaLink="false">http://blog.uxebu.com/?p=493</guid>
		<description><![CDATA[We have been writing and talking about EventNinja already for a bit. Now you can have it! Just visit EventNinja.net and test it on your iPhone and other mobile devices. EventNinja is on its way into the different AppStores and we will keep you updated on new versions coming out. What will you get? At [...]]]></description>
			<content:encoded><![CDATA[<p>We have been writing and <a href="http://twitter.com/EventNinja_app">talking about EventNinja</a> already for a bit. <strong>Now you can have it!</strong> Just visit <a href="http://www.eventninja.net">EventNinja.net</a> and test it on your iPhone and other mobile devices. EventNinja is on its way into the different AppStores and we will keep you updated on new versions coming out.<br />
What will you get? At first, you&#8217;re getting the best app out there to lead you around a conference like the <a href="http://mobile20.eu">mobile2.0 in Barcelona</a> in a few days on the 18th and 19th of June 2009. If you are attending be sure to have EventNinja on your mobile! So that you have all the info at hand when searching for the next talk to attend. It&#8217;s not just a list of all relevant upcoming web developer events on your phone (and browser). It is even more, you can get in depth info about the events, their schedule, all the twitter messages for an event, directions and many more features.<br />
If you are at the <a href="http://mobile20.eu">mobile2.0</a> be sure to visit us to get even more!</p>
<p>Enjoy the short video we prepared to give you an impression of what EventNinja can do</p>
<p><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/DClZnEaBHLI&#038;hl=en&#038;fs=1&#038;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/DClZnEaBHLI&#038;hl=en&#038;fs=1&#038;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></p>
<p><span id="more-493"></span></p>
<h2>EventNinja in Action</h2>
<p>The EventNinja widget contains multiple pages, as you are used to from mobile applications. The <em>home page</em> shows all the events, allows you to search and filter them. Along the top bar you have the search bar, the &#8220;Help&#8221; and the &#8220;About&#8221; pages linked.<br />
Clicking on the icon to the right of each event takes you to <em>the details page</em> of the event, from where you can go to multiple other places, like <em>the map</em>, to see where it exactly takes place,<em> the schedule</em> of the event. If the event has twitter tags saved for it can go to a page which shows you all <em>the latest twitter messages</em> flying in. Try it on <a href="http://www.eventninja.net">EventNinja.net</a> and explore the features.</p>
<h2>EventNinja Features</h2>
<h3>User Features</h3>
<ul>
<li>List of web developer events</li>
<li>Searchable and filterable by tags, location and full-text search</li>
<li>Exact location of the event</li>
<li>Watch all twitter messages for each event</li>
<li>Find out about details of an event</li>
</ul>
<h3>Technology Features</h3>
<ul>
<li>Events are stored, retrieved and filtered by a Google Calendar</li>
<li>Everything built on top of the <a href="http://www.dojotoolkit.org">Dojo Toolkit</a></li>
<li>pure HTML, CSS, JavaScript based widget</li>
<li>using <a href="http://www.phonegap.com">PhoneGap</a> to run on <a href="http://www.apple.com/iphone/">iPhone</a>, <a href="http://www.android.com/">Android</a> and <a href="http://www.blackberry.nl/">Blackberry</a></li>
<li>Plugin architecture, allows for a modular enhancement of the widget</li>
<li><strong>Fully</strong> customizable via client-side templates and CSS of course</li>
</ul>
<p>As you figure right from the list of features and cleverly combining them we can hook this widget onto any calendar, customize the features (via plugins), style and brand it the way we like it and have your custom widget.</p>
<p>This gives customization a far broader meaning. Just imagine combining the two components 1) base of the widget and 2) the twitter plugin. You get a widget which shows you all tweets for a certain event -that&#8217;s just a new widget itself, without writing a line of new code. Which again is a very different use case, than the widget you get here. Just hook in another plugin which allows replying via twitter and you get a full blown twitter client in the context of events.<br />
The limits of what is thinkable is just limited by the plugins you can write.</p>
<h2>EventNinja for the mobile2.0 Conference</h2>
<p>Mobile2.0 is the first conference where you can really use EventNinja to get all the info possible, the schedule, twitter messages, etc. There surely will follow many more conferences and events that EventNinja can and will be used at. See the screenshots below to get a feeling of what it looks like for this conference.</p>

<a href='http://uxebu.com/blog/2009/06/16/eventninja-a-mobile-must-have-widget-for-the-mobile20/screenshot-20090612-150714/' title='screenshot-20090612-150714'><img width="150" height="150" src="http://uxebu.com/blog/wp-content/uploads/2009/06/screenshot-20090612-150714-150x150.png" class="attachment-thumbnail" alt="screenshot-20090612-150714" title="screenshot-20090612-150714" /></a>
<a href='http://uxebu.com/blog/2009/06/16/eventninja-a-mobile-must-have-widget-for-the-mobile20/screenshot-20090612-150809/' title='screenshot-20090612-150809'><img width="150" height="150" src="http://uxebu.com/blog/wp-content/uploads/2009/06/screenshot-20090612-150809-150x150.png" class="attachment-thumbnail" alt="screenshot-20090612-150809" title="screenshot-20090612-150809" /></a>
<a href='http://uxebu.com/blog/2009/06/16/eventninja-a-mobile-must-have-widget-for-the-mobile20/screenshot-20090612-150819/' title='screenshot-20090612-150819'><img width="150" height="150" src="http://uxebu.com/blog/wp-content/uploads/2009/06/screenshot-20090612-150819-150x150.png" class="attachment-thumbnail" alt="screenshot-20090612-150819" title="screenshot-20090612-150819" /></a>
<a href='http://uxebu.com/blog/2009/06/16/eventninja-a-mobile-must-have-widget-for-the-mobile20/screenshot-20090612-150840/' title='screenshot-20090612-150840'><img width="150" height="150" src="http://uxebu.com/blog/wp-content/uploads/2009/06/screenshot-20090612-150840-150x150.png" class="attachment-thumbnail" alt="screenshot-20090612-150840" title="screenshot-20090612-150840" /></a>
<a href='http://uxebu.com/blog/2009/06/16/eventninja-a-mobile-must-have-widget-for-the-mobile20/screenshot-20090612-150917/' title='screenshot-20090612-150917'><img width="150" height="150" src="http://uxebu.com/blog/wp-content/uploads/2009/06/screenshot-20090612-150917-150x150.png" class="attachment-thumbnail" alt="screenshot-20090612-150917" title="screenshot-20090612-150917" /></a>
<a href='http://uxebu.com/blog/2009/06/16/eventninja-a-mobile-must-have-widget-for-the-mobile20/cap/' title='cap'><img width="150" height="150" src="http://uxebu.com/blog/wp-content/uploads/2009/06/cap-150x150.png" class="attachment-thumbnail" alt="cap" title="cap" /></a>

<h2>Are events missing?</h2>
<p>EventNinja for webdevelopers is driven by the great amount of community events.<br />
If you see that events are missing, please contact us and we will add them immediately. If you organize events yourself let us know as well. You can send any kind of info about the event, e.g. name, location, tags, speakers, twitter tags, schedule details, price, and much more.</p>
<h2>You want an EventNinja?</h2>
<p>Send an email to eventninja _ at _ uxebu.com if you are interested in a customized version of EventNinja, are interested in the technology or simply want to chat. At the <a href="htt[://www.mobile20.eu">mobile2.0</a> conference you will recognize us easily when you look for the guys with those caps, hurry, because we are spreading caps and maybe there will be many more wearing this cap :-).</p>
]]></content:encoded>
			<wfw:commentRss>http://uxebu.com/blog/2009/06/16/eventninja-a-mobile-must-have-widget-for-the-mobile20/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Some for-loop considerations</title>
		<link>http://uxebu.com/blog/2009/03/26/some-for-loop-considerations/</link>
		<comments>http://uxebu.com/blog/2009/03/26/some-for-loop-considerations/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 14:49:16 +0000</pubDate>
		<dc:creator>wolfram</dc:creator>
				<category><![CDATA[development tools]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[uxebu]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[coding style]]></category>
		<category><![CDATA[for-loop]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.uxebu.com/?p=142</guid>
		<description><![CDATA[We have been developing some coding style guide lines to produce better code and make our code easier maintainable and portable. Also thinking about code inspection tools and continuous integration techniques which analyze the code will profit from a well defined and verifyable style. While discussing a rather simple rule I thought this might be [...]]]></description>
			<content:encoded><![CDATA[<p>We have been developing some coding style guide lines to produce better code and make our code easier maintainable and portable. Also thinking about code inspection tools and continuous integration techniques which analyze the code will profit from a well defined and verifyable style.<br />
While discussing a rather simple rule I thought this might be interesting to delve into a bit. You will be surprised how much you can discuss about a simple thing such as a for-loop and that is not only true for JavaScript, I am sure.<br />
<span id="more-142"></span></p>
<p>Well, call me pedantic for even discussing this and seeing this as relevant. But everybody knows that adhering coding styles make programming in a team way more pleasant and it is just way more efficient to just code and not to style! Which includes not having to think about how to style the code, though I realize that a lot of programmers have a problem adapting to coding styles.<br />
We at uxebu basically defined that we are applying the coding guide lines of the project that we possibly contribute stuff back to. This means our JavaScript code applies the <a href="http://www.dojotoolkit.org/developer/StyleGuide">dojo coding style guide</a> and our python stuff (we use internally) applies the <a href="http://docs.djangoproject.com/en/dev/internals/contributing/#coding-style">django coding style guide</a>.</p>
<p>But let&#8217;s look at the for-loop now.</p>
<h2>The default</h2>
<p>The most common usage of a for loop is the following.</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>nodes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> node <span style="color: #339933;">=</span> nodes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// whatever</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Nothing spectacular here. But let&#8217;s take it apart a bit. There are two things that are commonly known that can be optimized.</p>
<ol>
<li>The comparison &#8220;i&lt;nodes.length&#8221; in line 1 evaluates the length of nodes on every iteration, if the nodes array is not modified while looping over it or the change to it is not relevant, this can be optimized.</li>
<li>Also the declaration of the variable &#8220;node&#8221; in line 2 is done multiple times, so this is just a small unnecessary thing to do.</li>
</ol>
<p>So let&#8217;s optimize the things we just found out.</p>
<h2>Version 2</h2>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> node<span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> len<span style="color: #339933;">=</span>nodes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; node <span style="color: #339933;">=</span> nodes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// whatever</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Another step on our way was to optimize the variable declarations and reducing their count from three down to one. In some code you can then see the following.</p>
<h2>Version 3</h2>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> node<span style="color: #339933;">,</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> len<span style="color: #339933;">=</span>nodes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; node <span style="color: #339933;">=</span> nodes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// whatever</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Actually we have already skipped a tiny step in between, very often you can see multiple var-statements as opposed to the already &#8220;squeezed&#8221; one-liner in line 1 above. The way of writing it as seen here, is reasonable if there are a couple other variables to be declared, you just need one var-statement. This will basically reduce the code size, if your minifier doesn&#8217;t already do that for you. <a href="http://wonko.com/post/try-to-use-one-var-statement-per-scope-in-javascript#comment-4819">As stated here</a> it seems to be specified to be irrelevant to performance. So event the argument under 2. against the first version (see above) is not very strong.<br />
Just a small side-note: the one line var-statement evaluates in declaration order, so something like this will work!</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> arr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> len <span style="color: #339933;">=</span> arr.<span style="color: #660066;">length</span><span style="color: #339933;">,</span> x <span style="color: #339933;">=</span> len<span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>The &#8220;len&#8221; and also &#8220;x&#8221; variables contain the proper content as you are expecting. The comma-separated var-statement evaluates the assignment expression by expression and steps on to the next assignment. Therefore &#8220;len&#8221; and &#8220;x&#8221; will have the proper values 3 and 2.<br />
But let&#8217;s go back to our for-loop.</p>
<h2>Version 4</h2>
<p>If the var-statement is outside the for-loop and especially if other variables (outside of the scope of the for-loop) are declared there the source code get&#8217;s blury and harder to read. For example:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> someVar <span style="color: #339933;">=</span> whatever<span style="color: #339933;">,</span> anotherVar <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> node<span style="color: #339933;">,</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> len<span style="color: #339933;">=</span>nodes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>The first two variable declarations (someVar and anotherVar) have nothing to do with the for-loop context, but the others do, so this blurs the source code and is prone to errors. Also if you separate this source code onto multiple lines like so:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> someVar <span style="color: #339933;">=</span> whatever<span style="color: #339933;">,</span> anotherVar <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; node<span style="color: #339933;">,</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> len<span style="color: #339933;">=</span>nodes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>it is still a possible point of failure. I for example, forgot the comma on line 1 which made this source code</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> someVar <span style="color: #339933;">=</span> whatever<span style="color: #339933;">,</span> anotherVar <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#93;</span><br />
&nbsp; &nbsp; node<span style="color: #339933;">,</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> len<span style="color: #339933;">=</span>nodes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>still work. But and this is a <strong>big but</strong>, the code get&#8217;s a different meaning now! First, line 1 will work, since the semicolon at the end of the line is not mandatory. And second (if not declared inside this scope before) the variables on line 2 are now defined in global scope. And that can really cause a hard to find bug!<br />
Another good reason for not doing this, is that extending the code may lead to developers adding code in between the var-declaration and the for-loop, for whatever reason. Then the variable declarations for the for-loop &#8220;drift away&#8221; and loose their context even a bit more. And the source code becomes harder to understand.</p>
<p>So we rather put all the variable declarations into the for-loop&#8217;s var-statement. Like so:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> someVar <span style="color: #339933;">=</span> whatever<span style="color: #339933;">,</span> anotherVar <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// This is outside the for-loop and also looks like it.</span><br />
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> len<span style="color: #339933;">=</span>nodes.<span style="color: #660066;">length</span><span style="color: #339933;">,</span> node<span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; node <span style="color: #339933;">=</span> nodes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// whatever</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now we have a pretty compact and well context-focused syntax for declaring variables needed within a for-loop. This code is nicely readable and has no impact on performance, even if in most cases good and maintainable code is worth more than the fastest code, but that&#8217;s a use case based decision! We are taking this as a standard for uxebu code.</p>
<p>What do you think? Let us know if you see potential for optimization.</p>
]]></content:encoded>
			<wfw:commentRss>http://uxebu.com/blog/2009/03/26/some-for-loop-considerations/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>The state of Ajax &#8211; great presentation</title>
		<link>http://uxebu.com/blog/2008/11/05/86/</link>
		<comments>http://uxebu.com/blog/2008/11/05/86/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 09:47:43 +0000</pubDate>
		<dc:creator>wolfram</dc:creator>
				<category><![CDATA[Tumbles]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[TAE]]></category>

		<guid isPermaLink="false">http://blog.uxebu.com/2008/11/05/86/</guid>
		<description><![CDATA[The state of Ajax &#8211; great presentation]]></description>
			<content:encoded><![CDATA[<p><a href="http://ajaxian.com/archives/the-ajax-universe-ben-and-dion-showcase-the-presentation-randomizer">The state of Ajax &#8211; great presentation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://uxebu.com/blog/2008/11/05/86/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>uxebu at the Ajax in Action</title>
		<link>http://uxebu.com/blog/2008/10/22/uxebu-at-the-ajax-in-action/</link>
		<comments>http://uxebu.com/blog/2008/10/22/uxebu-at-the-ajax-in-action/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 12:22:09 +0000</pubDate>
		<dc:creator>wolfram</dc:creator>
				<category><![CDATA[dojango]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[uxebu]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ajax in action]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.uxebu.com/?p=75</guid>
		<description><![CDATA[Just one week to go and we are glad that all three of us will make it to the Ajax in Action 2008 in Mainz (Germany). So if you like to contact us, meet in person or just have a chat (besides the virtual reality) let&#8217;s do it. If you are interested in JavaScript as [...]]]></description>
			<content:encoded><![CDATA[<p>Just one week to go and we are glad that all three of us will make it to the <a href="http://createordie.de/ajaxinaction/">Ajax in Action 2008 in Mainz (Germany)</a>. So if you like to contact us, meet in person or just have a chat (besides the virtual reality) let&#8217;s do it. If you are interested in JavaScript as we are, want to have an in depth <a href="http://dojotoolkit.org">dojo</a> discussion, feel like you need to know more about <a href="http://dojango.org">dojango</a> or just would like to talk AJAX with us, do it! We are looking forward to it.<br />
Of course we will have some stuff to share, we are going to hold four talks <a href="http://createordie.de/ajaxinaction/speaker/#3338">RIA/UI development with Dojo, Adobe AIR and Dojo, bringing the web to the desktop</a> from Nikolai and <a href="http://createordie.de/ajaxinaction/speaker/#3331">Architectures for scaling AJAX apps and Efficient AJAX/JavaScript Development</a> from me.<br />
<span id="more-75"></span></p>
<p>Besides holding talks, which occupies at least most of my brain time until I am done, we are really looking forward to getting to know better the AJAX Community here in Germany and we hope for a lot of input and to share ideas with like minded people. If there will be so much brain capital as there was in Boston for the <a href="http://blog.uxebu.com/2008/10/08/boston-wrap-up-dojo-12/">Ajax Experience two weeks ago</a>, we will need at least the rest of the year to digest it all. But hey, that is what we are out for. We want your input and we want to give input.</p>
<p>May be we will even try to have a gathering of some of the most interesting and most interested AJAX people that are coming to the conference in order to shoot a <a href="http://dojocampus.org/podcast/">dojo.cast()</a>, may be some kind of &#8220;conference edition&#8221;. Actually, that is just an idea I made up right this second while writing this, but I guess Nikolai and Pete won&#8217;t be too opposed to it.</p>
<p>Feel free to mail us or drop a comment if you like to meet up &#8211; no matter if dojo, ajax, javascript or whatever related.</p>
]]></content:encoded>
			<wfw:commentRss>http://uxebu.com/blog/2008/10/22/uxebu-at-the-ajax-in-action/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>BarCamp Munich wrap up (1/2)</title>
		<link>http://uxebu.com/blog/2008/10/17/barcamp-munich-wrap-up-12/</link>
		<comments>http://uxebu.com/blog/2008/10/17/barcamp-munich-wrap-up-12/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 14:07:52 +0000</pubDate>
		<dc:creator>wolfram</dc:creator>
				<category><![CDATA[dojo]]></category>
		<category><![CDATA[uxebu]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[barcamp]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[munich]]></category>

		<guid isPermaLink="false">http://blog.uxebu.com/?p=67</guid>
		<description><![CDATA[Now it&#8217;s almost a week ago, and I still haven&#8217;t written the more in depth article about the BarCamp Munich 2008, here it comes. As I have already said, the organization was great, first and foremost the people behind it, thanks a lot. But also Sun who provided the location and last but not least [...]]]></description>
			<content:encoded><![CDATA[<p>Now it&#8217;s almost a week ago, and I still haven&#8217;t written the more in depth article about the <a href="http://barcampmunich.mixxt.de/">BarCamp Munich 2008</a>, here it comes. As I have already said, the organization was great, first and foremost the people behind it, thanks a lot. But also Sun who provided the location and last but not least all participants. I will be there next year again, I am sure!<br />
<span id="more-67"></span></p>
<p><strong>Arrival</strong><br />
<a href="http://www.flickr.com/photos/zerok/2935049663/"><img style="float:right; margin:0 0 0.5em 0.5em;" src="http://farm4.static.flickr.com/3011/2935049663_67b8bd681d_m_d.jpg" alt="Going to the sessions" /></a>When I arrived there about 10:00 everybody started gathering in the cantine, I just had the time to grab a coffee and find <a href="http://schlueters.de/">Johannes</a> to have at least someone I know :-). Then the introduction round started and everybody stood up said his/her name and tagged himself with three tags. It went much faster than you would expect. About 15 minutes I would say, for about 300 people. Impressive, especially the ping pong strategy was somehow cool, going from one end of the room to the other, which was possible with two microphones. I realized, when it was my turn (and I was almost the last one) nobody had yet used the tag &#8220;ajax&#8221;, so I stood up and said &#8220;I am Wolfram Kriesing form uxebu, and my tags are: ajax, javascript and dojo&#8221;. Ok, I had passed the first test.</p>
<p><strong>dtrace</strong><br />
While all first time barcamper went to see a short session about how to barcamp Johannes showed me pretty impressive <a href="http://schlueters.de/blog/archives/82-DTraceing-around.html">stuff you can do with dtrace</a>. Just off of the top of his head he wrote a tiny script which just showed all &#8220;open&#8221; system calls, then we double clicked one of my files on the desktop and a hell lot of open calls were triggered, wow so much work for just looking at one file.<br />
If you want to get the hands deep into the gears of your system for whatever reason dtrace is waiting to be used. I will definitely need to dive into it for a project we are developing at uxebu. Unfortunately it is only available on Solaris and Mac OS X. But hey, most web devs are working on Macs, and since that is a dev tool it could be pretty useful to many.</p>
<p><strong>First two sessions</strong><br />
After introducing my two talks I went to see the session about <a href="http://blog.xonio.com/xonio_redaktion.php/2008/10/11/bcmuc08_die_china_session">the web in China</a>, it was nice and interesting information, but of too little use for me. Right after this, first session we all had lunch. Then I went to &#8220;presentations with storyboard&#8221;, where <a href="http://www.wissensagentur.net/">Alexandra Graßler</a> told us about how to do presentations best using a storyboard (some <a href="http://www.my-two-cents.de/2008/10/11/barcamp-munchen-zusammenfassung-tag-1">more info here</a>). It was very good I think, not too much new stuff but good the storyboard part was the good thing. Building a logical tree for your presentation on which you &#8220;crawl&#8221; along with your arguments in order to lead the listener to the assumptions you are going to make. I just need to pick the cherries from it try and practice that.</p>
<p><strong>My first session, Efficient JavaScript development</strong><br />
<a href="http://www.flickr.com/photos/zerok/2935058623/"><img style="float:left; margin:0 0.5em 0.5em 0;" src="http://farm4.static.flickr.com/3283/2935058623_6838e47fcb_m_d.jpg" alt="Efficient JS Development session" /></a>After that I had <a href="http://blog.uxebu.com/2008/10/13/barcampmunich-2008-slides/">my two sessions</a>, I guess two of the more technical sessions, which actually surprised me, but the number of listeners convinced me that there are interested techies there. Fortunately.<br />
For the first session &#8220;Efficient JavaScript development&#8221; I got some interesting input regarding the direction of the talk. <a href="http://blog.sperr-objekt.de/">Matthias Gutjahr</a> expected a bit more about how to write efficient JavaScript code. Right, the title might be a bit misleading. So I am trying to fix the direction of the talk, but I like the name and the wide range of possibilities it allows you to talk about. May be it pulls more people, then I only have to take care of meeting the expectations. I will try very hard! And since it was actually a subset and a test of what I want to <a href="http://createordie.de/ajaxinaction/session-tracks/?tid=960#session-8">talk about at the Ajax in Action 2008</a> in two weeks, it was a great first try. Thank you all for listening, the good questions and the input!</p>
<p><strong>My second talk, dojo toolkit</strong><br />
The next session &#8220;dojo toolkit&#8221; right after the first one, was targetted purely on dojo. I had converted the slides just one hour before to be real uxebu slides &#8211; but hey, what has to be has to be! The always again upcoming questions were about cometd, cross domain handling and some dojo internals.<br />
So I searched some URLs to show some of the examples that I may talked about or that target the mentioned topics.<br />
One is <a href="http://dante.dojotoolkit.org/dojobox/anon/demos/babelChat/demo.html">babel chat</a>, which Pete Higgins created and showed off a couple of times at the Ajax Experience in Boston. It&#8217;s a pretty neat application for showing off what <a href="http://cometdproject.dojotoolkit.org/">cometd</a> and <a href="http://docs.dojocampus.org/dojo/data">dojo.data</a> can do. You set your preferred language, log in and you can chat in your language, the answers come in your preferred language translated by google translate. We had a lot of fun with it, since the translations are often very funny. You know, the automatic translation stuff mostly sucks. But the show case is worth it with some extra fun included.<br />
Another thing that Pete had also created in Boston was the faces demo &#8220;<a href="http://dante.dojotoolkit.org/dojobox/anon/dojoc/demos/faces/demo.php">Create you own <del datetime="2008-10-17T13:11:26+00:00">dojo</del> javascript developer</a>&#8220;. You can flip parts of the faces and choose from various developers. You will get a lot to laugh! There is even a hall of shame now, check it out! It uses <a href="http://www.nicolarizzo.com/gamesroom/flip.html">dojox.fx.flip</a> from <a href="http://www.nicolarizzo.com">Nicola Rizzo</a>. Which allows you to flip layers and the cool thing about it is all done just by manipulating CSS properties.</p>
<p>This has already become a lot of text and because I am actually not a big friend of so much text I just stop it here and continue in a second article. (Or am I just too lazy right now :-)).</p>
<p>All <a href="http://www.flickr.com/photos/zerok/">pics form zerok</a>, thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://uxebu.com/blog/2008/10/17/barcamp-munich-wrap-up-12/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ajax with dojango (dojo+django)</title>
		<link>http://uxebu.com/blog/2008/07/26/ajax-with-dojango/</link>
		<comments>http://uxebu.com/blog/2008/07/26/ajax-with-dojango/#comments</comments>
		<pubDate>Sat, 26 Jul 2008 19:40:11 +0000</pubDate>
		<dc:creator>wolfram</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[dojango]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://blog.uxebu.com/?p=40</guid>
		<description><![CDATA[Ok, now you got dojango and you want to write an AJAX app. There are some basics that just need to be provided in order to make that a piece of cake. Dojango offers them. And this article will show you how to best plug those pieces together and get up and running with ajax [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, now you got <a href="http://code.google.com/p/dojango/">dojango</a> and you want to write an AJAX app. There are some basics that just need to be provided in order to make that a piece of cake. Dojango offers them. And this article will show you how to best plug those pieces together and get up and running with ajax and dojango.<br />
This article will show you how to simply pass data properly from the backend to the client.<br />
<span id="more-40"></span></p>
<p><strong>JSON communication with the server</strong><br />
There are enough use cases (and they are becoming more) when you want to get data from the server and the most common data format nowadays for that is <a href="http://en.wikipedia.org/wiki/JSON#Using_JSON_in_Ajax">JSON</a>, for various good reasons.<br />
Let&#8217;s construct a simple form who&#8217;s data we want to submit to the server and know if it all went ok or not. For now we just print the submitted data on the django console (from where you started the local dev server) and we let the user know about the submission with the small text &#8220;Submitted&#8221; beside the submit button.<br />
So let&#8217;s get started with the JavaScript side. Dojango luckily provides us with the basic infrastructure, so let&#8217;s create a template that extends <em>dojango/base.html</em> (it is available since the <em>settings.py</em> includes the app &#8220;dojango&#8221;, <a href="http://code.google.com/p/dojango/wiki/GettingStarted">see here for instructions</a>), that provides us with everything we need to have dojo running even the doctype of the document and HTML headers, just in short a valid HTML file, we only have to worry about our code.<br />
So let&#8217;s build the <em>simple.html</em> file in the templates folder of our django app (I called my app &#8220;core&#8221;).</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">{% extends &quot;dojango/base.html&quot; %}<br />
<br />
{% block dojango_page_title %}Simple AJAX with dojango{% endblock %}<br />
<br />
{% block dojango_header_extra %}<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; function userFormSubmit(){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var form = dojo.byId(&quot;userForm&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dojo.xhrPost({url:form.action,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handleAs: &quot;json&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; content:{surname:form.surname.value,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; firstname:form.firstname.value<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; load:function(response, ioArgs){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dojo.byId(&quot;info&quot;).innerHTML = &quot;Submitted&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
{% endblock %}<br />
<br />
{% block dojango_content %}<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;userForm&quot;</span> <span style="color: #000066;">onsubmit</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;userFormSubmit(); return false;&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/simple-ajax-set/&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; First name: <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;firstname&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Surname: <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;surname&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Submit&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">span</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;info&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">span</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a>&gt;</span><br />
{% endblock %}</div></td></tr></tbody></table></div>
<p>As you can see we are overriding a couple of blocks, that are defined in the <em>dojango/base.html</em>. The first one (line 3) is just for setting the page title, the second one (line 5) is for putting our JavaScript code inside html-head. And &#8220;dojango_content&#8221; (line 21) is finally the content of the body node.<br />
We also have to wire up the template to render when we access http://localhost:8000/simple/ and the AJAX method, that we submit the data to, like so in the <em>urls.py</em>:</p>
<div class="codecolorer-container python twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">conf</span>.<span style="color: black;">urls</span>.<span style="color: black;">defaults</span> <span style="color: #ff7700;font-weight:bold;">import</span> *<br />
<br />
urlpatterns <span style="color: #66cc66;">=</span> patterns<span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^dojango/'</span><span style="color: #66cc66;">,</span> include<span style="color: black;">&#40;</span><span style="color: #483d8b;">'dojango.urls'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^simple/'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'core.views.simple'</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^simple-ajax-set/'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'core.views.simple_ajax_set'</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
<span style="color: black;">&#41;</span></div></td></tr></tbody></table></div>
<p>We just added the two last lines that map our URLs (line 6 and 7) to the view functions.<br />
Our <em>views.py</em> just needs to implement these two functions, like this.</p>
<div class="codecolorer-container python twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">shortcuts</span> <span style="color: #ff7700;font-weight:bold;">import</span> render_to_response<br />
<span style="color: #ff7700;font-weight:bold;">from</span> dojango.<span style="color: black;">decorators</span> <span style="color: #ff7700;font-weight:bold;">import</span> json_response<br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> simple<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> render_to_response<span style="color: black;">&#40;</span><span style="color: #483d8b;">'simple.html'</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #66cc66;">@</span>json_response<br />
<span style="color: #ff7700;font-weight:bold;">def</span> simple_ajax_set<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; firstname <span style="color: #66cc66;">=</span> request.<span style="color: black;">POST</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'firstname'</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; surname <span style="color: #66cc66;">=</span> request.<span style="color: black;">POST</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'surname'</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> firstname<span style="color: #66cc66;">,</span> surname<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#123;</span><span style="color: #483d8b;">'success'</span>:<span style="color: #008000;">True</span><span style="color: black;">&#125;</span></div></td></tr></tbody></table></div>
<p>The function &#8220;simple&#8221; (line 4) uses the standard django way to render a view and return the content to the client. It finds the template <em>simple.html</em> in the app&#8217;s template path.<br />
The function &#8220;simple_ajax_set&#8221; (line 8) will receive our form data and (for now) only print them. You can see the first speciality here, it uses the decorator &#8220;json_response&#8221; that we imported from dojango.decorators. This decorator takes care of returning proper JSON data, all the data you stuff in there are returned to the client JSON encoded, it basically is <a href="http://wolfram.kriesing.de/blog/index.php/2007/json_encode-updated">json_encode as described here</a>. If you have AJAX calls and want to return JSON data, this is the easiest way to do it and it comes with dojango. It is a special (though very simple) implementation that has not made it&#8217;s way into the django core because it is really just AJAX-focused, while the django serializer is django model focused. Additionally this implementation solves a couple of problems and adds some features that are very useful when working with AJAX data, <a href="http://wolfram.kriesing.de/blog/index.php/2007/json-serialization-for-django">for more explainations see this article</a>.</p>
<p><strong>Handle the return</strong><br />
Now we can submit the form and see that the data got submitted. We don&#8217;t know yet if the data had been successfully handled on the server. So let&#8217;s add proper error handling.</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> userFormSubmit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> form <span style="color: #339933;">=</span> dojo.<span style="color: #660066;">byId</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;userForm&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; dojo.<span style="color: #660066;">xhrPost</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span>form.<span style="color: #660066;">action</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; handleAs<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; content<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>surname<span style="color: #339933;">:</span>form.<span style="color: #660066;">surname</span>.<span style="color: #660066;">value</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; firstname<span style="color: #339933;">:</span>form.<span style="color: #660066;">firstname</span>.<span style="color: #660066;">value</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; load<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #339933;">,</span> ioArgs<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>response.<span style="color: #660066;">success</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dojo.<span style="color: #660066;">byId</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;info&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Submitted successfully&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dojo.<span style="color: #660066;">byId</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;info&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Error: &quot;</span><span style="color: #339933;">+</span>response.<span style="color: #660066;">error</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; error<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// This happens on a 500 error or alikes.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dojo.<span style="color: #660066;">byId</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;info&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Error sending data.&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>If you looked into the return data (i.e. via FireBug) you might have seen that</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">{&quot;success&quot;:true}</div></td></tr></tbody></table></div>
<p>was returned. But until now this was passed into the load function (line 8) as a string, but we want them as JSON. So we have to tell the xhrPost() call to handle it as JSON (line 4). Now we can also evaluate the success value easily as shown in line 9. If the server returns</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">success</div></td></tr></tbody></table></div>
<p>with the value</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">false</div></td></tr></tbody></table></div>
<p>we know something went wrong on the server. Let&#8217;s implement on the server that the surname has to have at least three characters. In the case of an error the server returns the additional property &#8220;error&#8221; which we then show to the user (line 12) to inform him about the error.<br />
The function in line 15 handles all kind of connection and/or submission errors that may occur in a lower level. Make sure to not leave your users in the dark about this.<br />
Let&#8217;s look at the server code for that:</p>
<div class="codecolorer-container python twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">@</span>expect_post_request<br />
<span style="color: #66cc66;">@</span>json_response<br />
<span style="color: #ff7700;font-weight:bold;">def</span> simple_ajax_set<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; ret <span style="color: #66cc66;">=</span> <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; firstname <span style="color: #66cc66;">=</span> request.<span style="color: black;">POST</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'firstname'</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; surname <span style="color: #66cc66;">=</span> request.<span style="color: black;">POST</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'surname'</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>surname<span style="color: black;">&#41;</span><span style="color: #66cc66;">&lt;</span><span style="color: #ff4500;">3</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; ret<span style="color: black;">&#91;</span><span style="color: #483d8b;">'error'</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'Surname is too short.'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ret<span style="color: black;">&#91;</span><span style="color: #483d8b;">'success'</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #008000;">False</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> ret<span style="color: black;">&#91;</span><span style="color: #483d8b;">'success'</span><span style="color: black;">&#93;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Store the data here</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">pass</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> ret</div></td></tr></tbody></table></div>
<p>We extended the function a little bit to do some simple error checking. You can see that we add the key &#8220;error&#8221; to the ret dict, which is then passed to the client if the surname was shorter than three characters. The JSON string returned in this case is</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">{&quot;success&quot;: false, &quot;error&quot;: &quot;Surname is too short.&quot;}</div></td></tr></tbody></table></div>
<p>.<br />
Note that we didn&#8217;t explicitly set the value for</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">success</div></td></tr></tbody></table></div>
<p>to</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">True</div></td></tr></tbody></table></div>
<p>, the decorator</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">json_response</div></td></tr></tbody></table></div>
<p>handles that for us. If no exception is thrown it assumes that the function went ok and it can return</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">success=True</div></td></tr></tbody></table></div>
<p>. This comes in very handy, especially when you just have simple one task AJAX functions that i.e. just delete an item, you don&#8217;t have to return explicitly that the deletion went well,</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">json_response</div></td></tr></tbody></table></div>
<p>does that for you if you throw no exception. We just made it the default behavior since it was right for most of our use cases.</p>
]]></content:encoded>
			<wfw:commentRss>http://uxebu.com/blog/2008/07/26/ajax-with-dojango/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Rat out those security issues in your Web app</title>
		<link>http://uxebu.com/blog/2008/07/04/rat-out-those-security-issues-in-your-web-app/</link>
		<comments>http://uxebu.com/blog/2008/07/04/rat-out-those-security-issues-in-your-web-app/#comments</comments>
		<pubDate>Fri, 04 Jul 2008 09:01:26 +0000</pubDate>
		<dc:creator>wolfram</dc:creator>
				<category><![CDATA[Tumbles]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[XSRF]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://blog.uxebu.com/?p=25</guid>
		<description><![CDATA[Rat out those security issues in your Web app]]></description>
			<content:encoded><![CDATA[<p><a href="http://ajaxian.com/archives/ratproxy-rat-out-those-security-issues-in-your-web-app">Rat out those security issues in your Web app</a></p>
]]></content:encoded>
			<wfw:commentRss>http://uxebu.com/blog/2008/07/04/rat-out-those-security-issues-in-your-web-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

