<?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>Rochak Chauhan::Unpredictably Exciting &#187; Ajax</title>
	<atom:link href="http://rochakchauhan.com/blog/category/programming/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://rochakchauhan.com/blog</link>
	<description>Know your limits, but never stop trying to exceed them.</description>
	<lastBuildDate>Thu, 03 May 2012 11:48:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Reduce your exposure to AJAX threats</title>
		<link>http://rochakchauhan.com/blog/2008/02/18/reduce-your-exposure-to-ajax-threats/</link>
		<comments>http://rochakchauhan.com/blog/2008/02/18/reduce-your-exposure-to-ajax-threats/#comments</comments>
		<pubDate>Mon, 18 Feb 2008 11:35:47 +0000</pubDate>
		<dc:creator>rochakchauhan</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[AJAX threats]]></category>

		<guid isPermaLink="false">http://rochakchauhan.com/blog/2008/02/18/reduce-your-exposure-to-ajax-threats/</guid>
		<description><![CDATA[Three-step guide Fundamentally, there&#8217;s nothing terribly new about the problems posed by Asynchronous JavaScript and XML (AJAX) when it comes to security, we just need to apply some good old security principles to this new technology. The problems occur because, unfortunately, there are an awful lot of devils hidden inside the details. One major security &#8230; <a class="read-excerpt" href="http://rochakchauhan.com/blog/2008/02/18/reduce-your-exposure-to-ajax-threats/">Continue reading <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<h3 class="Standfirst">Three-step guide</h3>
<p id="Body">Fundamentally, there&#8217;s nothing terribly new about the problems posed by Asynchronous JavaScript and XML (AJAX) when it comes to security, we just need to apply some good old security principles to this new technology.</p>
<p>The problems occur because, unfortunately, there are an awful lot of devils hidden inside the details.</p>
<p id="MidArticleAd"><script type="text/javascript">     document.write(\'\x3Cscript src="http://ad.uk.doubleclick.net/adj/reg.developer.4159/security;\'+RegExCats+GetVCs()+\'chl=making_it;pid=\'+RegId+\';\'+RegKW+\'maid=\'+maid+\';test=\'+test+\';pf=\'+RegPF+\';dcove=d;sz=336x280;tile=3;ord=\' + rand + \'?" type="text/javascript">\x3C\/script>\');</script><script src="http://ad.uk.doubleclick.net/adj/reg.developer.4159/security;chl=making_it;pid=75053;maid=;test=;pf=0;dcove=d;sz=336x280;tile=3;ord=19693540643213?" type="text/javascript"></script><noscript></noscript></p>
<p>One major security challenge for AJAX applications is that moving your code to the client involves a ton of data formats, protocols, parsers, and interpreters. These include JavaScript, VBScript, Flash, JSON, XML, REST, XmlHttpRequest, XSLT, CSS and HTML in addition to your existing server-side technologies. As if that wasn&#8217;t enough, each of the AJAX frameworks has its own data formats and custom framework formats.</p>
<p>An application&#8217;s &#8220;attack surface&#8221; approximates the ways in which an attacker can cause damage to your application or its users. The more technologies you use, the bigger your attack surface.</p>
<p>Here, then, are three simple ways of reducing your AJAX application&#8217;s attack surface:</p>
<h3>Know what runs where</h3>
<p>AJAX is making it increasingly difficult to be sure where your code is going to run. Take the Google Web Toolkit (GWT) for example. You program in Java and the environment takes some of that code and compiles it to JavaScript that runs on the client. If you make a mistake and implement authentication, access control, validation, or other security checks in the code that runs on the client, an attacker can simply bypass them with Firebug.</p>
<p>Imagine you&#8217;ve carefully coded rules to be sure that administrative functions are never shown to ordinary users. This sounds good, but you forgot that the user interface code is running on the client. So the attacker uses Firebug to invoke the administrative functions. If the proper checks aren&#8217;t in place on the server side, the attacker just gained administrative rights. Many Rich Internet Application (RIA) frameworks also have this issue.</p>
<p>The solution is to be very careful about making the boundary between the client and the server very clear.</p>
<h3>Keep data separate from code</h3>
<p>Hackers frequently use a technique called &#8220;injection&#8221; to bury commands inside innocent-looking data and get interpreters to execute their commands for them. This simple trick is at the heart of many security attacks including SQL injection, command injection, LDAP injection, <a href="http://www.regdeveloper.co.uk/2008/01/07/xss_tactics_strategy/">XSS</a>, and buffer overflows. Preventing injection in a target-rich environment like the modern browser takes discipline.</p>
<p>The key to stopping injection attacks is never executing data that might contain code. But with AJAX, lots of data and code get passed around and mashed together in the DOM. There has never been a data structure that mixes together code and data more than modern HTML.</p>
<p>So be very careful with data that might include user input. Assume it&#8217;s an attack unless you&#8217;ve carefully canonicalized, validated, and properly encoded. Imagine you&#8217;re invoking a REST interface and the request contains user data. The response you receive is a JSON string that includes that user data. Don&#8217;t evaluate that string until you&#8217;re sure that there can&#8217;t be anything but safe data in there. Even just adding that data to the DOM might be enough to get it to execute if there&#8217;s JavaScript code buried in there.</p>
<h3>Beware encoding</h3>
<p>Encoding makes everything complicated. Attackers can hide their attacks inside innocent-looking data by encoding it. Back-end systems may recognize the encoding used and execute the attack. Or they may decode the attack and pass it on to a system that&#8217;s vulnerable to it.</p>
<p>Attackers may use multiple different encoding schemes, or even double encode to tunnel their attacks through innocent systems. There are dozens and dozens of encoding schemes and no way to tell which schemes will be recognized by the interpreters you&#8217;re using. This makes recognizing attacks very difficult, if not impossible.</p>
<p>Every time you send or receive data both sides have to know the intended encoding. Never try to make a &#8220;best effort&#8221; attempt to guess the right encoding. You can&#8217;t prevent an attacker from sending data with some other encoding through the channel, but you don&#8217;t have to execute it. Here are a few examples:</p>
<p>Set HTTP encoding in the header:</p>
<pre>     <font color="#0000ff">Content-Type: text/xml, charset=utf-8</font></pre>
<p>Use a meta tag in the HTML:</p>
<pre></pre>
<p>Set XML encoding in the first line of XML documents:</p>
<pre><font color="#0000ff">&lt;?xml version="1.0" encoding="utf-8"?&gt;</font></pre>
<h3>Nail it</h3>
<p>Remember, your AJAX application&#8217;s attack surface is under your control. The choices you make can drastically affect the size of your application&#8217;s attack surface. Be sure you ask questions about where your code runs, what data formats and protocols are involved, and which parsers and interpreters get invoked. And most importantly, be sure to nail down how you&#8217;re going to keep code and data separate.</p>
]]></content:encoded>
			<wfw:commentRss>http://rochakchauhan.com/blog/2008/02/18/reduce-your-exposure-to-ajax-threats/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>Streamline your search with Yahoo! Web Services and AJAX</title>
		<link>http://rochakchauhan.com/blog/2008/02/05/streamline-your-search-with-yahoo-web-services-and-ajax/</link>
		<comments>http://rochakchauhan.com/blog/2008/02/05/streamline-your-search-with-yahoo-web-services-and-ajax/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 16:57:10 +0000</pubDate>
		<dc:creator>rochakchauhan</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tech News]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[Yahoo]]></category>

		<guid isPermaLink="false">http://rochakchauhan.com/blog/2008/02/05/streamline-your-search-with-yahoo-web-services-and-ajax/</guid>
		<description><![CDATA[Despite what you might read and hear about Google&#8217;s web dominance, this is not Google-owned world. Yahoo! may be playing second fiddle to the internet&#8217;s favorite search and ads service, but it still plays one hell of a tune in terms of numbers of users and the services it offers. If you use Yahoo! for &#8230; <a class="read-excerpt" href="http://rochakchauhan.com/blog/2008/02/05/streamline-your-search-with-yahoo-web-services-and-ajax/">Continue reading <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Despite what you might read and hear about Google&#8217;s web dominance, this is not Google-owned world. Yahoo! may be playing second fiddle to the internet&#8217;s favorite search and ads service, but it still plays one hell of a tune in terms of numbers of users and the services it offers.</p>
<p>If you use Yahoo! for your web search, then Yahoo! provides web services that may be included in web applications to generate dynamic content for an input.</p>
<p id="MidArticleAd"><script type="text/javascript">     document.write(\'\x3Cscript src="http://ad.uk.doubleclick.net/adj/reg.developer.4159/code;\'+RegExCats+GetVCs()+\'chl=;pid=\'+RegId+\';\'+RegKW+\'maid=\'+maid+\';test=\'+test+\';pf=\'+RegPF+\';dcove=d;sz=336x280;tile=3;ord=\' + rand + \'?" type="text/javascript">\x3C\/script>\');</script><script src="http://ad.uk.doubleclick.net/adj/reg.developer.4159/code;vc=print.print;vc=dev.code;chl=;pid=0;maid=;test=;pf=1;dcove=d;sz=336x280;tile=3;ord=74835324578534?" type="text/javascript"></script><noscript></noscript></p>
<p>In this article, we follow up  Asynchronous JavaScript and XML (AJAX) to your Google search, by looking at adding AJAX to web search using Yahoo! Web Services in Oracle JDeveloper 11g. Why JDeveloper 11g? Because this provides a new feature for web and AJAX development &#8211; an integrated JavaScript editor.</p>
<h3>Limits of AJAX</h3>
<p>AJAX is a web technique to transfer XML data between a browser and a server without reloading the web page. Ajax is implemented using the <code>XMLHttpRequest</code> object.</p>
<p>A limitation of <code>XMLHttpRequest</code> is that AJAX requests may be made only to the same web server that serves the web page from where the AJAX request is sent. If the web application is running on one server and the web service is on another server a <code>XMLHttpRequest</code> request does not get sent. Various methods are available to send an AJAX request to a remote server some of which are digitally signing your scripts and using an alternative <code>XMLHttpRequest</code> API. One of the methods, which we shall discuss in this article, is to use a proxy web server that routes AJAX requests from the web application to the web service.</p>
<p>Yahoo! Web Services provide various web search services and content that may be included to develop dynamic web applications. Yahoo! Web Search AJAX Web Services have an advantage over the Google web search AJAX web services. Yahoo! Web Services have the provision to search within a context; contextual web search. For example, search for the term &#8220;Eclipse&#8221; in the context of &#8220;Java IDE&#8221;. The various Web Search Web Services provided by Yahoo! are discussed in following Table.</p>
<table border="1">
<tr>
<th>Web service</th>
<th>Description</th>
</tr>
<tr>
<td>Context search</td>
<td>The contextual web search service returns web pages that match a query within a specified context</td>
</tr>
<tr>
<td>Related suggestion</td>
<td>Provides suggestions for related queries based on the submitted query</td>
</tr>
<tr>
<td>Spelling suggestion</td>
<td>Provides suggested spellings for a specified term</td>
</tr>
<tr>
<td>Web search</td>
<td>Provides a web search service using REST (Representational State Transfer)</td>
</tr>
</table>
<p>Before Yahoo! Web Service may be used, register with <a href="https://login.yahoo.com/config/login_verify2?.src=devnet&amp;.done=https%3A%2F%2Fdeveloper.yahoo.com%2Fwsregapp%2Findex.php">Yahoo Web Services</a> (<span class="URL">https://login.yahoo.com/config/login_verify2?.src=devnet&amp;.done=https%3A%2F%2Fdeveloper.yahoo.com%2Fwsregapp%2Findex.php</span>) to obtain an application identity with which Yahoo! Web Services may be accessed.</p>
<h3>Create a web application</h3>
<p>First, create a JDeveloper application, <code>WebSearchApp</code>, and project, <code>WebSearchWebService</code>. Create a JSP file, <code>input.jsp</code>, in the project. The web application URL, which is used to register with Yahoo! Web Services, is <code>http://127.0.0.1:8988/WebSearchApp-WebSearchWebService-context-root/input.jsp</code>. In the web application we shall use the Contextual Web Search service to submit a context-base web search query.</p>
<p>The request URL for the contextual web search web service is <code>http://search.yahooapis.com/WebSearchService/V1/contextSearch</code>. The required request parameters to a contextual web search query are <code>appid</code> and <code>context</code>. The value of the <code>appid</code> parameter is the application ID provided by Yahoo! Web Services and the context parameter specifies the context string in which the web search query is sent.</p>
<hr class="PageBreak" />The XML response returned by the Contextual Web Search service conforms to the XML Schema <code>http://search.yahooapis.com/WebSearchService/V1/WebSearchResponse.xsd</code>. In the <code>input.jsp</code> add a form containing fields for application ID, query, results, and context. The form may be submitted using GET or POST, but to use a context with many search terms use the POST method.</p>
<h3>Send an AJAX request</h3>
<p>To send an AJAX request we shall use a proxy servlet that routes the <code>XMLHttpRequest</code> from the browser to the Yahoo! Web Service. If an <code>XMLHttpRequest</code> is sent without a proxy servlet the <code>XMLHttpRequest</code> does not get sent and an error, such as the one below, is generated.</p>
<pre>Error: uncaught exception: Permission denied to call method XMLHttpRequest.open</pre>
<p>A proxy servlet may be developed or the <a href="http://www.servletsuite.com/servlets/httpproxy.htm">HTTP proxy servlet</a> (<span class="URL">http://www.servletsuite.com/servlets/httpproxy.htm</span>) may be used. Download <code>httpProxyPackage.jar</code>. Add the proxy servlet JAR file to the Libraries of the <code>WebSearchWebService</code> project. To the <code>web.xml</code> file add <code>&lt;servlet/&gt;</code> and <code>&lt;servlet-mapping/&gt;</code> elements for the proxy servlet.</p>
<pre>&lt;servlet&gt;         &lt;servlet-name&gt;HttpProxy&lt;/servlet-name&gt;         &lt;servlet-class&gt;com.jsos.httpproxy.HttpProxyServlet&lt;/servlet-class&gt;         &lt;init-param&gt;             &lt;param-name&gt;host&lt;/param-name&gt;             &lt;param-value&gt;http://search.yahooapis.com/WebSearchService/V1/contextSearch&lt;/param-value&gt;         &lt;/init-param&gt;     &lt;/servlet&gt;     &lt;servlet-mapping&gt;         &lt;servlet-name&gt;HttpProxy&lt;/servlet-name&gt;         &lt;url-pattern&gt;/servlet/yahoo&lt;/url-pattern&gt;     &lt;/servlet-mapping&gt;</pre>
<p>The procedure to send an AJAX request is as follows:</p>
<ol>
<li>Initiate an AJAX request from an HTML event such as a button click</li>
<li>Create a <code>XMLHttpRequest</code> object</li>
<li>Open a connection with the web service URL using the open() method of the <code>XMLHttpRequest</code> object</li>
<li>Register a callback function to be invoked when the Ajax request is complete</li>
<li>Send the AJAX request with the send() method</li>
<li>Update the web page with the web service response</li>
</ol>
<p>In the <code>input.jsp</code>, to the input element of type button add a <code>onclick</code> event handler to invoke a JavaScript function <code>displaySearchResults()</code>. In the <code>displaySearchResults</code> function create an <code>XMLHttpRequest</code> object. <code>XMLHttpRequest</code> is supported as a native object in some browsers such as Netscape 6 or later and Internet Explorer 7 and as an ActiveXObject in other browsers such as IE 6.</p>
<p>Specify the proxy servlet URL to which an AJAX request is to be sent. Obtain the values for query, results and context request parameters from the input form. Open an <code>XMLHttpRequest</code> request using the <code>open()</code> method. Register a callback function that is to be invoked when the request state changes using the <code>onreadystatechange</code> property of the <code>XMLHttpRequest</code> object. Send the <code>XMLHttpRequest</code> request using the <code>send()</code> method. In the callback function check if the request is complete and invoke the JavaScript function <code>processResponse()</code> to update the web page with the Web Service response. The complete <code>input.jsp</code> is available in <a href="http://regmedia.co.uk/2008/01/29/yahooajax_resources.zip">this</a> (<span class="URL">http://regmedia.co.uk/2008/01/29/yahooajax_resources.zip</span>) zipped folder.</p>
<h3>Integrated JavaScript editor</h3>
<p>JDeveloper 11g includes an integrated JavaScript editor for creating JavaScript. In the previous section we added the JavaScript directly to the JSP, but the JavaScript may also be created in a separate <code>.js</code> file and the <code>.js</code> file added to the JSP using the <code>&lt;script/&gt;</code> tag. Create a JavaScript file by selecting File&gt;New and in the New Gallery window Web Tier&gt;HTML&gt;JavaScript File. Copy the JavaScript from the <code>input.jsp</code> JSP to the JavaScript file and delete the JavaScript from the JSP.</p>
<hr class="PageBreak" />One of the features of the JavaScript editor is syntax highlighting. To add syntax highlighting select Tools&gt;Preferences and in the Preferences window Code Editor&gt;Syntax Colors. Select JavaScript in the Language list. The Font Style, Foreground color and Background color may be set for the different JavaScript constructs in the Syntax Colors window.JavaScript editor also provides code completion. As the JavaScript syntax varies in the different browsers we need to specify the browser for which code completion is to be implemented. Select JavaScript Editor in the Preferences window and select a Target Browser for code completion. In the JavaScript file right click and select Source&gt;Completion Insight or Smart Completion Insight for code insight.</p>
<p>Another useful feature of the JavaScript editor is Go To Declaration, to navigate to or from a JavaScript variable or function. You can try this by selecting a use for the variable <code>xmlHttpRequest</code> and then right click and select Go To Declaration to go to the declaration of the <code>xmlHttpRequest</code> variable. JavaScript editor also provides brace matching and code folding.</p>
<p>Error underling and error audits are also helpful. Here&#8217;s a simple way to test them: add an error by removing the &#8216;{&#8216; for a function declaration. An error analysis will then be run and the error underlined. Usages for a variable or function may be retrieved by selecting the variable/function and selecting Find Usages. For example, select <code>xmlHttpRequest</code>, right click and select Find Usages. The usages of the <code>xmlHttpRequest</code> variable get listed in the log window.</p>
<p>A JavaScript file is integrated with the Structure pane from which different variables and functions may be navigated to. JavaScript editor also provides refactoring to rename or delete a variable or function. To refactor, right click and select Refactor&gt;Rename or Delete Safely. To add the JavaScript file to the <code>input.jsp</code> drag and drop the file from the Application navigator to the JSP. A <code>&lt;script/&gt;</code> element for the JavaScript file gets added to the JSP.</p>
<h3>Run the AJAX web search</h3>
<p>Next, we shall run the AJAX web application to send a query using AJAX an update the web page with the query response. Right click on <code>input.jsp</code> and select Run. In the web search form specify a query term and a context term. As an example, search for the term &#8220;AJAX&#8221; in the context of &#8220;web services&#8221;. Click on the Submit Query button. The web page gets updated with the AJAX web service response.</p>
<p>More than one context terms may be specified and the number of results to be returned may also be specified. As an example specify results as five and specify context terms as &#8220;web services&#8221;, &#8220;XML&#8221;, and &#8220;ADF&#8221; for query term &#8220;AJAX&#8221;. The specified number of web pages get displayed for the context based web search.</p>
<h3>Conclusion</h3>
<p>You now have the recepie for building fast and efficient web services. Contextual web search using Yahoo Web Services will help you narrow down your search results. The addition of AJAX will help reduce response times and the amount of network bandwidth consumed as the complete web page is not reposted.</p>
]]></content:encoded>
			<wfw:commentRss>http://rochakchauhan.com/blog/2008/02/05/streamline-your-search-with-yahoo-web-services-and-ajax/feed/</wfw:commentRss>
		<slash:comments>514</slash:comments>
		</item>
		<item>
		<title>7 Deadly Sins of AJAX application development</title>
		<link>http://rochakchauhan.com/blog/2008/01/09/7-deadly-sins-of-ajax-application-development/</link>
		<comments>http://rochakchauhan.com/blog/2008/01/09/7-deadly-sins-of-ajax-application-development/#comments</comments>
		<pubDate>Wed, 09 Jan 2008 09:12:39 +0000</pubDate>
		<dc:creator>rochakchauhan</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Sins in AJAX]]></category>

		<guid isPermaLink="false">http://rochakchauhan.com/blog/2008/01/09/7-deadly-sins-of-ajax-application-development/</guid>
		<description><![CDATA[At first blush, those pitfalls may seem avoidable through sheer common sense, and to a degree, that&#8217;s true. But AJAX apps bristle with architectural differences from its DHTML forebears. No matter how much common sense you bring to the application development task, it is still good to learn from the mistakes of those who have &#8230; <a class="read-excerpt" href="http://rochakchauhan.com/blog/2008/01/09/7-deadly-sins-of-ajax-application-development/">Continue reading <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>At first blush, those pitfalls may seem avoidable through sheer common sense, and to a degree, that&#8217;s true. But AJAX apps bristle with architectural differences from its DHTML forebears. No matter how much common sense you bring to the application development task, it is still good to learn from the mistakes of those who have preceded you. We&#8217;ll call these mistakes our Seven Deadly Sins, but they are by no means the whole story.</p>
<p>In fact, before you commit any of the deadly sins, you&#8217;re much more likely to commit a few lesser sins. So we&#8217;ll start with those. These are the ones that make everybody&#8217;s list. These mistakes are so common that you can find most of them in a simple Google search.</p>
<p><strong>The Seven Lesser Sins </strong></p>
<p><strong>1.</strong><strong>Misuse of the Back Button &#8211;</strong> This is the one mistake everyone&#8217;s going to have on their list. The Back Button has become a user expectation in many kinds of Web apps. Many new AJAX developers drop a Back Button into their AJAX app and promptly break it, for several reasons. First, JavaScript isn&#8217;t the friendliest language for it; and second, AJAX design requires a new way of thinking.<br />
It&#8217;s not always readily apparent to a new AJAX developer that &#8220;Back&#8221; isn&#8217;t best. &#8220;Back&#8221; is a feature you&#8217;ll need at a page-update point or more often, when you want an event-specific &#8220;Undo&#8221; feature. Think this through before you code, or you&#8217;ll end up doing it twice.<br />
<strong>2.</strong><strong>Not telling the user what&#8217;s happening &#8211;</strong> Part of how AJAX works is that it doesn&#8217;t use conventional Web UI page loading. So you need to explicitly design some visual cue to let the user know what&#8217;s happening.<br />
<strong>3.</strong><strong>Neglecting Links &#8212; </strong>Here&#8217;s another AJAX standard blunder: neglecting URLs that can be cut-and-pasted for uses outside the app. How many times have we grabbed a URL and e-mailed it to someone? When you&#8217;re using AJAX, the only way to provide your user with useful cut-and-pasteable URLs is to manually provide them. Why? Because in an AJAX app, <em>the server is not providing the page</em>: JavaScript is dynamically generating it! Don&#8217;t neglect your users&#8217; potential interest in this all-too-common feature of Web apps. Take pains to provide URLs, since the server won&#8217;t.<br />
<strong>4.</strong><strong>Trading content control for page control &#8212; </strong>Breaking with the traditional client-server interaction is a wonderful gift, if you&#8217;re seeking dynamic content control. But it&#8217;s also a curse: rewriting highly-specific areas of a page to fine-tune a user&#8217;s interactive experience does indeed give you fine control, but this pulls you away from the big picture.<br />
All too often, we focus on processing some sector of the page and forget that the page isn&#8217;t going to be refreshed by the server. This can lead to a fragmented page, a confusing user experience, wherein the screen they&#8217;re looking at can be out-of-date with itself! Take care to keep your attention on the entire page; make sure that any dynamic content event evokes changes everywhere the user will need to see them.<br />
<strong>5.</strong><strong>Killing spiders &#8211;</strong> The upside of AJAX is the truckloads of text you can feed a page without a reload. And the downside of AJAX is the truckloads of text you can feed a page without a reload. If the app is intended to be search-engine-friendly &#8212; well, you can imagine. Whatever is happening in the guts of the page, be sure to plant plenty of stable text up top, for the spiders to play with.<br />
<strong>6.</strong><strong>Producing unspeakable text &#8212; </strong>AJAX doesn&#8217;t support many character sets. This isn&#8217;t a life-or-death limitation, but forgetting it can create real problems. Your basic character set is UTF-8. Don&#8217;t forget to properly encode whatever JavaScript is sending, and remember to set the server-side character set for content.<br />
<strong>7.</strong><strong>Not letting the JavaScript-challenged user know what&#8217;s going on.</strong> There are browsers out there that don&#8217;t have JavaScript enabled, and users out there who don&#8217;t understand immediately what that means. Be sure to clue them in.</p>
<p>Truth to tell, most of those are common-sense issues. The real killers are less obvious.</p>
<p><strong>The Seven Deadly AJAX Sins</strong></p>
<p><strong>1.</strong><strong>Letting memory leak &#8211;</strong> Anyone who has worked in development for very long understands cyclic references and the danger they pose to memory management. JavaScript, the workhorse of AJAX, is a memory-managed language. What that means is that JavaScript has built-in garbage collection, so that it sniffs out variables no longer accessible by any reference path and de-allocates the memory they&#8217;re using.<br />
That&#8217;s fine as a general principle; but you can&#8217;t count on it to keep your memory usage optimised, because of those cyclic references, when a Model-layer object is referencing a View element and vice versa. Nulling the object nulls the element, in principle, but if there&#8217;s a backward reference from element to object, then the garbage collector won&#8217;t touch the object.<br />
Now, here&#8217;s where it gets tricky: in the Document Object Model, any DOM node that&#8217;s part of the document tree may be referenced by virtue of its presence in the tree, whether it&#8217;s explicitly referenced by another object or not! So any object you tag for garbage collection that is back-referenced by a DOM node must be explicitly nulled in that direction, or its memory remains allocated!<br />
<strong>2.</strong><strong>Not knowing what &#8220;asynchronous&#8221; means &#8211;</strong> Asynchrony can be really unsettling to a user unaccustomed to it, and this can be ironic, since the Web apps you&#8217;ll design and build for those users wouldn&#8217;t find them at all unsettling <em>if they were desktop apps</em>. This is a crucial design point! Most Web apps are functionally very similar to their desktop counterparts. But in a Web app, there&#8217;s a looming characteristic that sets it apart: <em>user expectations</em>.<br />
Users carry a very different set of biases and anticipations into a session with a Web browser that they don&#8217;t tote into a desktop app exchange. So while it may be incredibly cool and efficient to have myriad responses trotting back to the page from the server, and the page revising itself in the meantime, it can be deeply disorienting to the user to see this constant barrage of change. For this reason, you need to apply two rules, and consider them with <em>every</em> change that comes into the user&#8217;s field-of-vision: If the update is not immediately essential to the user, make the update unobtrusive, so that it does not distract; and if the update is vital to the user&#8217;s interaction with the app, make its presence on the page clear and prominent.<br />
<strong>3.</strong><strong>Keeping the server in the dark &#8211;</strong> The decoupling of client and server has a huge downside that seldom occurs to us up-front. Server-side apps know all and see all: every exception, every reload, every event can be watched and recorded, and of course the server knows exactly what the client looks like, because the server basically wrote whatever&#8217;s on the screen.<br />
In an AJAX app, this isn&#8217;t the case. Stuff happens, and it happens independently of the server, and this means that there can be problems on the client side that the server won&#8217;t immediately be privy to. Capture and log events and exceptions on the client side, in a place and manner that enables the server to home in on problems that require its intervention as soon as possible.<br />
<strong>4.</strong><strong>Getting lazy with GET &#8211;</strong> GET is for retrieving data; POST is for setting it. Don&#8217;t use GET when you know you shouldn&#8217;t, even if you think it will do no harm. GET operations change state, and links that change state are confusing to users; most are accustomed to links as guides to navigation, not function.<br />
<strong>5.</strong><strong>Not accounting for data type &#8211;</strong>JavaScript, isn&#8217;t part of the .NET Framework. While this may draw tears of sorrow, it presents us with an example of a problem you&#8217;ll eventually run into: making certain that JavaScript understands the data types of the platform it&#8217;s running on, and vice versa, be it .NET or otherwise. There are various converters available to you, and you should seek them out. The Ajax.NET Pro library, for instance, offers converters that can convert objects between .NET and JavaScript Object Notation.<br />
<strong>6.</strong><strong>Some apps just don&#8217;t know when to shut up &#8211;</strong> Dynamic generation of content, with no dependency on page-reload, can be disastrous if left open-ended. How many Web pages have you seen that were longer than the Congressional Record? If Web pages that go on forever are a confusing nightmare for users, just imagine how they&#8217;ll feel about an <em>application</em> that goes on and on and on. Make your Web app pages dynamic, but build in some practical limits.<br />
<strong>7.</strong><strong>Keep your JavaScript out of your DOM &#8212; </strong>Remember that AJAX is built on the Model-View-Controller structure. Take this seriously. JavaScript belongs in the Model layer, DOM in the View layer, and the Controller is their marriage counselor. Make sure your Web document has the same content independent of JavaScript (this helps with the JavaScript-disabled user) &#8212; except when the content itself is only meaningful or practical if the user can use JavaScript. In that instance, create that content with JavaScript.</p>
]]></content:encoded>
			<wfw:commentRss>http://rochakchauhan.com/blog/2008/01/09/7-deadly-sins-of-ajax-application-development/feed/</wfw:commentRss>
		<slash:comments>343</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
