<?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>Query7 &#187; JavaScript</title>
	<atom:link href="http://query7.com/category/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://query7.com</link>
	<description>PHP, Javascript, Python and Web Development</description>
	<lastBuildDate>Sat, 25 Jun 2011 21:29:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>NodeJS cURL Tutorial</title>
		<link>http://query7.com/nodejs-curl-tutorial</link>
		<comments>http://query7.com/nodejs-curl-tutorial#comments</comments>
		<pubDate>Mon, 28 Mar 2011 01:34:25 +0000</pubDate>
		<dc:creator>logan</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[nodejs]]></category>

		<guid isPermaLink="false">http://query7.com/?p=1369</guid>
		<description><![CDATA[<p>NodeJS is a powerful evented Javascript platform running on top of Google&#8217;s V8 javascript engine. Over the last year the popularity of NodeJS has increased greatly, as shown by the number of discussions on programming forums such as Hacker News, Reddit and Stackoverflow. Despite this NodeJS is still young and it falls short to Python and Ruby when it comes to the number and range of libraries and modules available.</p>
<h3>The Problem</h3>
<p>I wanted to convert one of my web scraping applications I made in PHP to NodeJS. The application interacts with SOCKS4 and SOCKS5 proxies using PHP&#8217;s cURL bindings. Unfortunately there are no cURL bindings (or SOCKS protocol wrappers) written for NodeJS. NodeJS does come with an HTTP client module that can issue web requests, however it doesn&#8217;t support SOCKS proxies.</p>
<h3>The Solution</h3>
<p>Although there are no specific NodeJS bindings for cURL, we can still issue cURL requests via the command line interface. NodeJS comes with the <em>child_process</em> module which easily allows us to start processes and read their output. Doing so is fairly straight forward. We just need to import the <a href="http://nodejs.org/docs/v0.4.3/api/child_processes.html#child_process.exec">exec</a> method from the <a href="http://nodejs.org/docs/v0.4.3/api/child_processes.html">child_process</a> module and call it. The first parameter is the command&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>NodeJS is a powerful evented Javascript platform running on top of Google&#8217;s V8 javascript engine. Over the last year the popularity of NodeJS has increased greatly, as shown by the number of discussions on programming forums such as Hacker News, Reddit and Stackoverflow. Despite this NodeJS is still young and it falls short to Python and Ruby when it comes to the number and range of libraries and modules available.</p>
<h3>The Problem</h3>
<p>I wanted to convert one of my web scraping applications I made in PHP to NodeJS. The application interacts with SOCKS4 and SOCKS5 proxies using PHP&#8217;s cURL bindings. Unfortunately there are no cURL bindings (or SOCKS protocol wrappers) written for NodeJS. NodeJS does come with an HTTP client module that can issue web requests, however it doesn&#8217;t support SOCKS proxies.</p>
<h3>The Solution</h3>
<p>Although there are no specific NodeJS bindings for cURL, we can still issue cURL requests via the command line interface. NodeJS comes with the <em>child_process</em> module which easily allows us to start processes and read their output. Doing so is fairly straight forward. We just need to import the <a href="http://nodejs.org/docs/v0.4.3/api/child_processes.html#child_process.exec">exec</a> method from the <a href="http://nodejs.org/docs/v0.4.3/api/child_processes.html">child_process</a> module and call it. The first parameter is the command we want to execute and the second is a callback function that accepts <em>error</em>, <em>stdout</em>, <em>stderr</em>.</p>
<h3>The Code</h3>
<pre>var util = require('util');
var exec = require('child_process').exec;

var command = 'curl -sL -w "%{http_code} %{time_total}\\n" "http://query7.com" -o /dev/null'

child = exec(command, function(error, stdout, stderr){

	console.log('stdout: ' + stdout);
	console.log('stderr: ' + stderr);

	if(error !== null)
	{
		console.log('exec error: ' + error);
	}

});</pre>
<p>This returns the HTTP code and time it took for the request to be issued:</p>
<pre>stdout: 200 0.710</pre>
<h3>Conclusion</h3>
<p>Although NodeJS is still young and bindings haven&#8217;t been made for alot of C libraries, the code above shows how you can still interact with the functionality they provide. That being said, the number of NodeJS modules is growing weekly. Be sure to keep an eye on the <a href="https://github.com/joyent/node/wiki/modules">module wiki</a> and <a href="http://search.npmjs.org/">npm registry</a> for a list of modules.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/nodejs-curl-tutorial/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cloud9 IDE Review</title>
		<link>http://query7.com/cloud9-ide-review</link>
		<comments>http://query7.com/cloud9-ide-review#comments</comments>
		<pubDate>Mon, 25 Oct 2010 05:33:51 +0000</pubDate>
		<dc:creator>Adit Gupta</dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://query7.com/?p=697</guid>
		<description><![CDATA[<p><span style="font-family: Arial, sans-serif;">A couple of weeks ago, </span><span style="color: #0000ff;"><span style="text-decoration: underline;"><a href="http://www.ajax.org/"><span style="font-family: Arial, sans-serif;">Ajax.org</span></a></span></span><span style="font-family: Arial, sans-serif;"> released a new IDE for Javascripters known as Cloud9. It&#8217;s an open   source project built on </span><span style="color: #0000ff;"><span style="text-decoration: underline;"><a href="http://nodejs.org/"><span style="font-family: Arial, sans-serif;">Node.js</span></a></span></span><span style="font-family: Arial, sans-serif;">. In case you don&#8217;t know, Node.js is an implementation of Server Side JavaScript (SSJS) and is now actively being used for SSJS development. Since Cloud9 IDE is built on top of Node.js, it has an integrated debugger for Node.JS applications. In this article we’ll be taking a look at  various features of Cloud9 such as those mentioned above, but for now let’s begin with installation.</span></p>
<p><strong>Installation</strong></p>
<p><span style="font-family: Arial, sans-serif;">Installation is very simple provided you&#8217;re familiar with the terminal. There are </span><span style="font-family: Arial, sans-serif;">three</span><span style="font-family: Arial, sans-serif;"> ways to install Cloud9: </span></p>
<p><span style="font-family: Arial, sans-serif;">1.</span><span style="font-family: Arial, sans-serif;"> If you&#8217;ve Git installed on your system then you can get the code repository directly from Github. Just enter the following command in your terminal:</span></p>
<p><span style="font-family: Courier, 'Courier New', serif;"><span style="font-size: small;"><code>git clone git://github.com/ajaxorg/cloud9.git</code></span></span></p>
<p><span style="font-family: Courier, 'Courier New', serif;"><span style="font-size: x-small;"><a href="http://query7.com/wp-content/uploads/im012.jpg"><img class="alignnone size-full wp-image-706" src="http://query7.com/wp-content/uploads/im012.jpg" alt="Installing Cloud9 via GitHub" width="550" height="170" /></a></span></span></p>
<p><span style="font-family: Arial, sans-serif;">After Git checkout, enter the following command to install all the submodules and run the IDE:</span></p>
<p><span style="font-family: Courier, 'Courier New', serif;"><span style="font-size: small;"><code>bin/cloud9.sh</code></span></span></p>
<p><span style="font-family: Courier, 'Courier New', serif;"><span style="font-size: small;"><a href="http://query7.com/wp-content/uploads/im02.jpg"><img class="alignnone size-full wp-image-703" src="http://query7.com/wp-content/uploads/im02.jpg" alt="Building Cloud9 IDE" width="550" height="300" /></a></span></span></p>
<p><span style="font-family: Arial, sans-serif;">The editor will open in your default browser after all the submodules have been installed.</span></p>
<p><span style="font-family: Arial, sans-serif;"><a href="http://query7.com/wp-content/uploads/im03.jpg"><img class="alignnone size-full wp-image-704" src="http://query7.com/wp-content/uploads/im03.jpg" alt="Cloud9 IDE" width="550" height="300" /></a></span></p>
<p><span style="font-family: Arial, sans-serif;"><a href="http://query7.com/wp-content/uploads/im03.jpg"></a></span><span style="font-family: Arial, sans-serif;">You can also install Cloud9 via NPM </span></p>
<p><span style="font-family: Courier, 'Courier New', serif;"><span style="font-size: small;"><code>npm install cloud9</code></span></span></p>
<p><span style="font-family: Arial, sans-serif;">or by downloading the source code from 	Github.</span></p>
<p><span style="color: #bf2500;"><span style="font-size: small;"><strong><span style="color: #000000;">Review</span></strong></span></span></p>
<p><span style="font-family: Arial, sans-serif;">Cloud9&#8242;s UI is similar to Eclipse IDE, so Eclipse</span>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: Arial, sans-serif;">A couple of weeks ago, </span><span style="color: #0000ff;"><span style="text-decoration: underline;"><a href="http://www.ajax.org/"><span style="font-family: Arial, sans-serif;">Ajax.org</span></a></span></span><span style="font-family: Arial, sans-serif;"> released a new IDE for Javascripters known as Cloud9. It&#8217;s an open   source project built on </span><span style="color: #0000ff;"><span style="text-decoration: underline;"><a href="http://nodejs.org/"><span style="font-family: Arial, sans-serif;">Node.js</span></a></span></span><span style="font-family: Arial, sans-serif;">. In case you don&#8217;t know, Node.js is an implementation of Server Side JavaScript (SSJS) and is now actively being used for SSJS development. Since Cloud9 IDE is built on top of Node.js, it has an integrated debugger for Node.JS applications. In this article we’ll be taking a look at  various features of Cloud9 such as those mentioned above, but for now let’s begin with installation.</span></p>
<p><strong>Installation</strong></p>
<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } --><span style="font-family: Arial, sans-serif;">Installation is very simple provided you&#8217;re familiar with the terminal. There are </span><span style="font-family: Arial, sans-serif;">three</span><span style="font-family: Arial, sans-serif;"> ways to install Cloud9: </span></p>
<p><span style="font-family: Arial, sans-serif;">1.</span><span style="font-family: Arial, sans-serif;"> If you&#8217;ve Git installed on your system then you can get the code repository directly from Github. Just enter the following command in your terminal:</span></p>
<p><span style="font-family: Courier, 'Courier New', serif;"><span style="font-size: small;"><code>git clone git://github.com/ajaxorg/cloud9.git</code></span></span></p>
<p><span style="font-family: Courier, 'Courier New', serif;"><span style="font-size: x-small;"><a href="http://query7.com/wp-content/uploads/im012.jpg"><img class="alignnone size-full wp-image-706" src="http://query7.com/wp-content/uploads/im012.jpg" alt="Installing Cloud9 via GitHub" width="550" height="170" /></a></span></span></p>
<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } --><span style="font-family: Arial, sans-serif;">After Git checkout, enter the following command to install all the submodules and run the IDE:</span></p>
<p><span style="font-family: Courier, 'Courier New', serif;"><span style="font-size: small;"><code>bin/cloud9.sh</code></span></span></p>
<p><span style="font-family: Courier, 'Courier New', serif;"><span style="font-size: small;"><a href="http://query7.com/wp-content/uploads/im02.jpg"><img class="alignnone size-full wp-image-703" src="http://query7.com/wp-content/uploads/im02.jpg" alt="Building Cloud9 IDE" width="550" height="300" /></a></span></span></p>
<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } --><span style="font-family: Arial, sans-serif;">The editor will open in your default browser after all the submodules have been installed.</span></p>
<p><span style="font-family: Arial, sans-serif;"><a href="http://query7.com/wp-content/uploads/im03.jpg"><img class="alignnone size-full wp-image-704" src="http://query7.com/wp-content/uploads/im03.jpg" alt="Cloud9 IDE" width="550" height="300" /></a></span></p>
<p><span style="font-family: Arial, sans-serif;"><a href="http://query7.com/wp-content/uploads/im03.jpg"></a></span><span style="font-family: Arial, sans-serif;">You can also install Cloud9 via NPM </span></p>
<p><span style="font-family: Courier, 'Courier New', serif;"><span style="font-size: small;"><code>npm install cloud9</code></span></span></p>
<p><span style="font-family: Arial, sans-serif;">or by downloading the source code from 	Github.</span></p>
<p><span style="color: #bf2500;"><span style="font-size: small;"><strong><span style="color: #000000;">Review</span></strong></span></span></p>
<p><span style="font-family: Arial, sans-serif;">Cloud9&#8242;s UI is similar to Eclipse IDE, so Eclipse users will find it simple and intuitive to use. While not as robust as Eclipse, it supports various features required in an IDE like Nested syntax highlighting, auto indentation, line numbering, bracket matching and debugging. Moreover, Cloud9 uses pure DOM methods along with virtual view port to render everything, the upshot being: no scalability problems. Nice! Note that DOM is used only for drawing purposes and does not store states. Plugins are also supported in Cloud9. In fact, various features like the filesystem, debugger, console and search are all basically plugins for Cloud9. On top of all this, users can also write extensions for Cloud9. </span><span style="color: #0000ff;"><span style="text-decoration: underline;"><a href="http://cloud9ide.posterous.com/writing-an-extension-for-cloud9-javascript-id"><span style="font-family: Arial, sans-serif;">This tutorial</span></a></span></span><span style="font-family: Arial, sans-serif;"> covers everything you need to know about writing extensions for Cloud9.</span></p>
<p><span style="font-family: Arial, sans-serif;">The biggest advantage of using Cloud9 is that you can rapidly develop and debug SSJS applications without any fuss. It&#8217;s true that you can find many JavaScript IDE&#8217;s on the Web, but most of them do not have good support for SSJS development. The fact that Cloud9 is built on top of Node.js makes it an ideal IDE for developing SSJS applications. That being said, it&#8217;s still buggy. Not only did it crash a couple of times while debugging, it&#8217;s also not completely stable on Safari and Internet Explorer7/8. Some other features missing from this IDE are code folding and source control integration. Still, judging by the exponential increase in its user base, there’s hope that these features will soon be available.</span></p>
<p><span style="font-size: small;"><strong>Final Verdict</strong></span></p>
<p><span style="font-family: Arial, sans-serif;">So, the big question is: &#8220;Do we need another IDE for JS development?&#8221; Well, it all boils down to your requirements. There&#8217;s no need to switch to Cloud9 if you&#8217;re just working with Client-Side JS(</span><span style="font-family: Arial, sans-serif;">CSJS</span><span style="font-family: Arial, sans-serif;">). There are already some very good editors/IDE&#8217;s for CSJS like Aptana, Eclipse for JS, IntelliJS and Textmate. However, if you&#8217;re into SSJS development, I strongly recommend trying out Cloud9. </span></p>
<p><span style="font-family: Arial, sans-serif;">(And if you do take Cloud9 for a spin, we’d love to see your reviews in the comments section!)</span></p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/cloud9-ide-review/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Codemirror &#8211; javascript syntax highlighting</title>
		<link>http://query7.com/codemirror-javascript-syntax-highlighting</link>
		<comments>http://query7.com/codemirror-javascript-syntax-highlighting#comments</comments>
		<pubDate>Wed, 22 Jul 2009 21:05:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://query7.com/?p=512</guid>
		<description><![CDATA[<p><a href="http://marijn.haverbeke.nl/codemirror/">CodeMirror</a> is an on the fly syntax highlighting engine, written in Javascript. Like CodePress (the syntax highlighter used in the latest version of wordpress for editing plugins), it can highlight many different languages (PHP, JS, HTML, CSS to name a few). This tutorial will show you how to implement CodeMirror on your site, there is a great article written by the author of this library <a href="http://marijn.haverbeke.nl/codemirror/story.html">here</a> on how it works under the hood.</p>
<h3>Installation</h3>
<p>Download the latest version from the CodeMirror <a href="http://marijn.haverbeke.nl/codemirror/">website</a>. As of today, it is version 0.62. After you unzip it you will see 3 directories &#8211; <em>js</em>, <em>css</em> and <em>contrib</em>. <em>contrib</em> holds parsers that other people have written such as the lua, python and PHP. <em>css</em> holds the color schemes for syntax highlighting and <em>js</em> contains the necessary scripts for CodeMirror to run.</p>
<h3>Basic Usage</h3>
<p>If we have a textarea with an id of code that we wanted to turn into a CodeMirror editor with a MirrorFrame(more on this later) then we would use the code below. Note that we need to specify where the parserfiles and stylesheets for the particular type of syntax (in this case javascript) are located.</p>
<pre>
  var textarea = document.getElementById('code');</pre><p>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://marijn.haverbeke.nl/codemirror/">CodeMirror</a> is an on the fly syntax highlighting engine, written in Javascript. Like CodePress (the syntax highlighter used in the latest version of wordpress for editing plugins), it can highlight many different languages (PHP, JS, HTML, CSS to name a few). This tutorial will show you how to implement CodeMirror on your site, there is a great article written by the author of this library <a href="http://marijn.haverbeke.nl/codemirror/story.html">here</a> on how it works under the hood.</p>
<h3>Installation</h3>
<p>Download the latest version from the CodeMirror <a href="http://marijn.haverbeke.nl/codemirror/">website</a>. As of today, it is version 0.62. After you unzip it you will see 3 directories &#8211; <em>js</em>, <em>css</em> and <em>contrib</em>. <em>contrib</em> holds parsers that other people have written such as the lua, python and PHP. <em>css</em> holds the color schemes for syntax highlighting and <em>js</em> contains the necessary scripts for CodeMirror to run.</p>
<h3>Basic Usage</h3>
<p>If we have a textarea with an id of code that we wanted to turn into a CodeMirror editor with a MirrorFrame(more on this later) then we would use the code below. Note that we need to specify where the parserfiles and stylesheets for the particular type of syntax (in this case javascript) are located.</p>
<pre>
  var textarea = document.getElementById('code');
  var editor = new MirrorFrame(CodeMirror.replace(textarea), {
    height: "350px",
    content: textarea.value,
    parserfile: ["tokenizejavascript.js", "parsejavascript.js"],
    stylesheet: "css/jscolors.css",
    path: "js/",
    autoMatchParens: true
  });
</pre>
<p>The result would be:<br />
<img src="http://query7.com/wp-content/uploads/2009/07/default1.png" alt="default1" title="default1" width="565" height="367" class="alignnone size-full wp-image-517" /></p>
<h3>MirrorFrame</h3>
<p>The MirrorFrame class extends the syntax highlighter and makes the editor feel more of a true editor &#8211; with a toolbar/buttons. You can find the source of the MirrorFrame implementation in <em>js/mirrorframe.js</em>. As an example we&#8217;ll take the &#8216;get current line number&#8217; function. It references <em>this</em> which in our case is the current editor. There are alot of functions CodeMirror makes available (<a href="http://marijn.haverbeke.nl/codemirror/manual.html#programming">list here</a>), you can write your own functions and attach them to a button in your own MirrorFrame editor.</p>
<pre>
  line: function() {
    alert("The cursor is currently at line " + this.mirror.currentLine());
    this.mirror.focus();
  },
</pre>
<h3>CodeMirror</h3>
<p>We can pass many configuration options to the CodeMirror class when we instantiate it such as whether we want line numbering and the size of tab width. An example below:</p>
<pre>
editor = CodeMirror.fromTextArea(textarea, {
content: textarea.value,
parserfile: ["parser/tokenizejavascript.js", "parser/parsejavascript.js"],
stylesheet: "css/editor_colours/jscolours.css",
path: "js/",
autoMatchParens: true,
width: '100%',
height: '100%',
textWrapping: false,
lineNumbers: true,
tabMode: 'spaces',
iframeClass: 'ifc',
indentUnit: 4
});
</pre>
<p><img src="http://query7.com/wp-content/uploads/2009/07/custom.png" alt="custom" title="custom" width="435" height="321" class="alignnone size-full wp-image-528" /></p>
<p>There are also 2 events available for the developer to use. <em>onChange</em> and <em>initCallBack</em>. initCallBack is called when the editor has loaded and is ready for the user to start entering code (remember an iframe is created, additional javascript files are loaded). onChange occurs whenever a change is made in the editor itself. If we wanted to build an on-the-fly code tester, and needed to fetch the code from the editor whenever the code in the editor changed, then we would do the following:</p>
<pre>
  var editor = CodeMirror.fromTextArea(textarea, {
    height: "350px",
    content: textarea.value,
    parserfile: ["tokenizejavascript.js", "parsejavascript.js"],
    stylesheet: "css/jscolors.css",
    path: "js/",
    autoMatchParens: true,
    onChange: function (n) { alert(editor.getCode()); },
  });
</pre>
<p><img src="http://query7.com/wp-content/uploads/2009/07/alert1.png" alt="alert1" title="alert1" width="626" height="354" class="alignnone size-full wp-image-531" /></p>
<p>This was just a quick look at CodeMirror, but hopefully you can appreciate just how powerful it is. It could be used in your website&#8217;s admin interface to alter code on the fly, or be used in <a href="http://www.appcelerator.com/">Titanium</a> or <a href="http://www.adobe.com/products/air/">AIR</a> to create a desktop IDE in HTML/Javascript.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/codemirror-javascript-syntax-highlighting/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dual form processing</title>
		<link>http://query7.com/dual-form-processing</link>
		<comments>http://query7.com/dual-form-processing#comments</comments>
		<pubDate>Tue, 14 Apr 2009 14:18:39 +0000</pubDate>
		<dc:creator>Kishore Nallan</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.webdevelopmentbits.com/?p=477</guid>
		<description><![CDATA[<p>Recently, a client of mine wanted a single web form, residing on the localhost to submit the form contents to a database in the localhost, and as well as to a web server simultaneously. Although this sounds like an unnecessary duplication of data, my client wanted some of the form data to be stored on the localhost for the intranet applications to use. Achieving this functionality <em>would have</em> been a piece of cake, if we were not handicapped by the unavailability of cross-domain AJAX. For those of us familiar with AJAX, we know that we cannot send an AJAX request to a remote server due to security reasons &#8211; atleast not in a reliable, hack-less way.</p>
<p>So, instead of looking for a pure AJAX solution, I decided to implement this functionality by using a combination of AJAX (for the localhost) and a traditional PHP POST request (for the web server). The trick here is to execute the AJAX call before the form is submitted &#8211; by catching the form submission event using JavaScript. Once the AJAX call is successful, we allow the default form submission to take place. In case there is an error with our AJAX call, we should&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Recently, a client of mine wanted a single web form, residing on the localhost to submit the form contents to a database in the localhost, and as well as to a web server simultaneously. Although this sounds like an unnecessary duplication of data, my client wanted some of the form data to be stored on the localhost for the intranet applications to use. Achieving this functionality <em>would have</em> been a piece of cake, if we were not handicapped by the unavailability of cross-domain AJAX. For those of us familiar with AJAX, we know that we cannot send an AJAX request to a remote server due to security reasons &#8211; atleast not in a reliable, hack-less way.</p>
<p>So, instead of looking for a pure AJAX solution, I decided to implement this functionality by using a combination of AJAX (for the localhost) and a traditional PHP POST request (for the web server). The trick here is to execute the AJAX call before the form is submitted &#8211; by catching the form submission event using JavaScript. Once the AJAX call is successful, we allow the default form submission to take place. In case there is an error with our AJAX call, we should stop the propogation of the traditional form submission too.</p>
<p>Ok, so let&#8217;s start off with a simple example &#8211; a no-frills form with a few fields.</p>
<pre>

&lt;form method="post" id="webform" action="http://www.example.com/path/to/PHPscript.php"&gt;

&lt;label for="firstname"&gt;first name:&lt;/label&gt;
&lt;input type="text" name="firstname" id="firstname" value="" /&gt;

&lt;label for="lastname"&gt;last name:&lt;/label&gt;
&lt;input type="text" name="lastname" id="lastname" value="" /&gt;

&lt;label for="email" id="l_email"&gt;email address:&lt;/label&gt;
&lt;input type="text" name="email" id="email" value="" /&gt;

&lt;input type="submit" name="Submit" id="submit_butt" value="Submit" /&gt;
&lt;input type="reset" /&gt;

&lt;/form&gt;
</pre>
<p>When the above form is submitted as it is, the form contents will be sent to the PHP script in the webserver. As I mentioned earlier, what we need to do now is &#8220;catch&#8221; this form submission event and insert our AJAX call before that. Let&#8217;s see how we can do that now. We will be using jQuery for our JavaScript needs.</p>
<pre>

$(document).ready(function(){
$("#webform").submit( function()
{
var success = -1;

$.post("localScript.php",
{
firstname: $("#firstname").val(),
lastname: $("#lastname").val(),
email: $("#email").val()
},

function(response){

if(response.status == "0")
success = false;
else
success = true;

}, "json");

var d = new Date();
var t = d.getSeconds();

while(success==-1)
{
var d = new Date();
if(d.getSeconds() - t &gt; 4)
{
success = false;
break;
}
}

return success;
});
});
</pre>
<p>We set-up an event handler using jQuery, which fires whenever the form is submitted. We then make an AJAX call to the localhost to submit the form contents. We have a callback function which checks the status of the AJAX call. In case, any error occurs on the localhost, an error code can be returned (in our case, the status value will be 0) and we have to stop the form submission by returning &#8220;false&#8221; from the event handler function. This will stop the default action of the submit button, i.e. it will prevent the HTTP form submission.</p>
<p>This is achieved using a hack. Since the script will not wait for the callback function to return, the next statement, i.e. the &#8220;return&#8221; statement will be executed immediately after the $.post() call is made to the server. However, we cannot return from the function without knowing whether the operation on the backend succeeded or not. Since, JavaScript does not natively have any sleep()-like function, we have to force our script to get into a blocked state using a while() loop. We then manually terminate the while loop if we did not hear back from the server within a &#8220;few&#8221; seconds. In our example we have defined the timeout to be 4 seconds. In case we don&#8217;t hear from the server within this time, we will terminate the form submission by returning a &#8220;false&#8221;. This elaborate hack is required to ensure that we do not proceed to the next stage without knowing what happened to the data we submitted to the localhost.</p>
<p>If everything goes well in the localhost, the contents of the form will be processed and stored in the localhost database by the PHP script we have called using AJAX. The submit event handler will then return &#8220;true&#8221;. This would in turn cause the form to be submitted to the PHP script on the remote server, as defined in the action attribute of the &lt;form&gt; tag. Once the form is submitted, the browser requests, and loads this PHP script. The PHP scripts recieves the form contents as POST variables and saves them (by perhaps, storing them in a database).</p>
<p>We are not done yet, though. We still have to send the user back to a page on the localhost once the PHP script has finished processing and storing the form contents. We do that by:</p>
<pre>
</pre>
<pre>$redirect_url = "http://localhost/path/to/some/page";
header( 'Location: ' . $redirect_url );
exit;</pre>
<p>It is important that the header() is called <em>before</em> any actual output is sent to the browser. For example, you should not have any echo statement, or raw HTML output before calling the header().</p>
<p>That&#8217;s about it! Now we are really done! In most cases, you will notice that this entire process is so slick that your user would hardly notice the redirection from the page on the webserver to the page on the localhost! I have put together a barebones HTML page containing the code fragments above, which you can download for your reference and use from <a href="http://labs.sourcebits.com/wdb/dual_form_processing_demo.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/dual-form-processing/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No IE6 support on new W3C website?</title>
		<link>http://query7.com/no-ie6-support-on-new-w3c-website</link>
		<comments>http://query7.com/no-ie6-support-on-new-w3c-website#comments</comments>
		<pubDate>Fri, 27 Mar 2009 14:00:59 +0000</pubDate>
		<dc:creator>Dilip Shukla</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[IE6]]></category>
		<category><![CDATA[W3]]></category>
		<category><![CDATA[Web Standards]]></category>

		<guid isPermaLink="false">http://www.webdevelopmentbits.com/?p=445</guid>
		<description><![CDATA[<p><a title="World Wide Web Consortium" href="http://www.w3.org" target="_blank">W3.org</a> is overhauling its website in order to make it more user-friendly and quiet people who used to wonder (including me) why the administrator body of web have such dull, flat, unorganized and old fashioned website?</p>
<p>The new website looks more attractive and organized. 10 minutes tour of new website <a title="10 Minutes Tour of http://beta.w3.org/" href="http://dotsub.com/view/41e149bd-8b98-4103-a9f8-c96787497211" target="_blank">can be found here</a>. In contrast with the previous version, this new website uses rich content presentation, including JavaScript.</p>
<p>The website uses <a title="Download jQuery 1.3.2 from Google Code" href="http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.3.2.min.js" target="_blank">jQuery 1.3.2</a>, a very known and popular JavaScript library, instead of pure JavaScript. This is very good news and a big leap towards streamlining the use of JavaScript frameworks, specially in case of jQuery. In addition of core jQuery framework, <a title="Beta World Wide Web Consortium" href="http://beta.w3.org" target="_blank">beta.w3.org</a> also uses jQuery plugins (e.g.: <a title="jQuery Cycle Plugin" href="http://malsup.com/jquery/cycle/" target="_blank">http://malsup.com/jquery/cycle/</a>), to enhance the user experience.</p>
<p>The biggest news of the day is w3.org beta website doesn&#8217;t render correctly in IE6. It&#8217;s supposed to be a strong argument for web developers in order to inspire and take initiative towards to stop exclusive coding to render their websites correctly in IE6.</p>
<p style="text-align: center;"><img class="size-full wp-image-451 aligncenter" src="http://query7.com/wp-content/uploads/ie6.jpg" alt="" width="500" height="428" /></p>
]]></description>
			<content:encoded><![CDATA[<p><a title="World Wide Web Consortium" href="http://www.w3.org" target="_blank">W3.org</a> is overhauling its website in order to make it more user-friendly and quiet people who used to wonder (including me) why the administrator body of web have such dull, flat, unorganized and old fashioned website?</p>
<p>The new website looks more attractive and organized. 10 minutes tour of new website <a title="10 Minutes Tour of http://beta.w3.org/" href="http://dotsub.com/view/41e149bd-8b98-4103-a9f8-c96787497211" target="_blank">can be found here</a>. In contrast with the previous version, this new website uses rich content presentation, including JavaScript.</p>
<p>The website uses <a title="Download jQuery 1.3.2 from Google Code" href="http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.3.2.min.js" target="_blank">jQuery 1.3.2</a>, a very known and popular JavaScript library, instead of pure JavaScript. This is very good news and a big leap towards streamlining the use of JavaScript frameworks, specially in case of jQuery. In addition of core jQuery framework, <a title="Beta World Wide Web Consortium" href="http://beta.w3.org" target="_blank">beta.w3.org</a> also uses jQuery plugins (e.g.: <a title="jQuery Cycle Plugin" href="http://malsup.com/jquery/cycle/" target="_blank">http://malsup.com/jquery/cycle/</a>), to enhance the user experience.</p>
<p>The biggest news of the day is w3.org beta website doesn&#8217;t render correctly in IE6. It&#8217;s supposed to be a strong argument for web developers in order to inspire and take initiative towards to stop exclusive coding to render their websites correctly in IE6.</p>
<p style="text-align: center;"><img class="size-full wp-image-451 aligncenter" src="http://query7.com/wp-content/uploads/ie6.jpg" alt="" width="500" height="428" /></p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/no-ie6-support-on-new-w3c-website/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>See, Yes! Yes! – GO</title>
		<link>http://query7.com/see-yes-yes-go</link>
		<comments>http://query7.com/see-yes-yes-go#comments</comments>
		<pubDate>Tue, 09 Dec 2008 21:35:10 +0000</pubDate>
		<dc:creator>Dilip Shukla</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Web Standard]]></category>

		<guid isPermaLink="false">http://www.webdevelopmentbits.com/?p=326</guid>
		<description><![CDATA[Modular CSS needs to be developed and all inherited properties needs to commented within CSS declaration so one don't repeat same CSS again and selectors needs to named by some naming convention (e.g. prefixing every declaration by module).

Modules needs to be devised in such way so it remain plug and play if plugged in different application.]]></description>
			<content:encoded><![CDATA[<h3>ID vs Class Vs Tag Vs Pseudo selectors</h3>
<p>:</p>
<p>All CSS developers know this fact there are verity of CSS selectors, CSS rules can be applied by using any one or combination of available selectors. We can apply CSS rules by inline CSS as value of style attribute of HTML tags or internal CSS by using style tag, or we can go for external style sheet. Inline CSS is bad and must be avoided. Inline style declarations should be limited to for some run time CSS manipulation only.</p>
<p>In summery using external CSS is preferred way, Its success depends on use of inline or internal CSS, since in effectiveness of application of CSS rules hierarchy, inline CSS is topmost level after that comes internal CSS and external CSS comes bellow them.</p>
<p>Same way &#8216;id&#8217; is above &#8216;class&#8217; in hierarchy of effectiveness of CSS selectors. Id can&#8217;t be used more than once in a page (its preferred to use one id for same element throughout application not only withing page).</p>
<p>Rigid element&#8217;s CSS should be served by using &#8216;id&#8217; CSS selectors, which will be used only once e.g. header, footer etc. Elements with dynamic nature having shared or inherited property with possible multiple occurrence need fetch CSS rules by &#8216;class&#8217; selectors.</p>
<p>Use of &#8216;tag&#8217; selectors can be decided by doing some research on default look and feel of elements of application. psudo CSS selectors can be used if backward compatibility with older browsers not needed.</p>
<p>Inheritance playes a great role in  in this that&#8217;s why planning is uttermost important. we should always keep in mind we are just contributing in development of some application which might have multiple developers hence coding must stick to requirements and standards of application so any one can understand and edit code of each other.</p>
<p>Modular CSS needs to be developed and all inherited properties needs to commented within CSS declaration so one don&#8217;t repeat same CSS again and selectors needs to named by some naming convention (e.g. prefixing every declaration by module).</p>
<p>Modules needs to be devised in such way so it remain plug and play if plugged in different application.</p>
<h3>Resources</h3>
<p>:</p>
<ul>
<li><a href="http://www.smashingmagazine.com/2008/11/12/12-principles-for-keeping-your-code-clean/">Make your markup clean</a></li>
<li><a href="http://www.jquery.com">Don&#8217;t fear to java script RIA is future. Jquery might be good place to start (and possibly end of search).</a></li>
<li><a href="http://www.smashingmagazine.com">Keep a tab on latest, fresh and trust worthy tips, tricks, trends, news etc related to web development.</a></li>
<li><a href="http://code.google.com/p/doctype/">Get benefit and give benefit by being active part of revolution in web development. Join the wiki maintained by web developers for web developer from Google. </a></li>
<li><a href="http://www.alistapart.com/">Know more about standards, stick to them and force them upon you, make web development your passion and web standards your religion. </a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/see-yes-yes-go/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Philosophy of Object Oriented Programming and Software Design</title>
		<link>http://query7.com/philosophy-of-object-oriented-programming-and-software-design</link>
		<comments>http://query7.com/philosophy-of-object-oriented-programming-and-software-design#comments</comments>
		<pubDate>Sat, 01 Nov 2008 14:33:25 +0000</pubDate>
		<dc:creator>yaapa</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Object-Oriented Programming]]></category>
		<category><![CDATA[philosophy]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.webdevelopmentbits.com/?p=241</guid>
		<description><![CDATA[Now, I am no expert in OOP or software design, but here's a philosophy which might help you make the most of what you know about OOP and software design.]]></description>
			<content:encoded><![CDATA[<p>Now, I am no expert in OOP or software design, but here&#8217;s a philosophy which might help you make the most of what you know about OOP and software design. I have observed and have read reports that people absorb most information when it&#8217;s presented in lists, preferably bulleted. So without any further ramling, I present you my bulleted philosophy of OOP and Software Design.</p>
<ul>
<li>It&#8217;s not how much and what you know; but what you can do with what you know, which&#8217;s important.</li>
</ul>
<ul>
<li>Ability to implement Polymorphism, Inheritance, private, public namespaces, static methods etc is no guarantee you are a good OO developer.</li>
</ul>
<ul>
<li>OOP is useless if you don&#8217;t use it to create good software design (architecture).</li>
</ul>
<ul>
<li>Using packages, classes, etc does not guarantee good software design.</li>
</ul>
<ul>
<li>When designing your software, think of it as an electronic device you are designing.</li>
</ul>
<ul>
<li>Sketch out the &#8216;electronic device&#8217;. Label the different components, list their functionalities.</li>
</ul>
<ul>
<li>Stay hungry, stay foolish.</li>
</ul>
<p>That&#8217;s it for today. I hope you are blessed with more knowledge, and the ability to make the best use of them.  Adios!</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/philosophy-of-object-oriented-programming-and-software-design/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>jQuery AJAX Tutorial Pt2</title>
		<link>http://query7.com/jquery-ajax-tutorial-pt2</link>
		<comments>http://query7.com/jquery-ajax-tutorial-pt2#comments</comments>
		<pubDate>Tue, 13 May 2008 04:35:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://www.query7.com/?p=50</guid>
		<description><![CDATA[<p>Heres Part 2 of the jQuery AJAX login tutorial. If you haven&#8217;t already, i suggest you read part 1 located <a href="http://www.query7.com/jquery-ajax-login-series-pt1/">here</a>.</p>
<p>We are going to start writing the PHP code to process the form. This is fairly basic stuff, using <em>$_POST</em> to get the values from the form, then checking them against pre-assigned values, if they match, then echo approved, if they don&#8217;t then echo denied.</p>
<pre lang="php"></pre>
<p>So at the end of this stage, you will have an HTML form set up and this PHP file. You can enter the username Panzer and the password of query7 into the form and it will return Logged in.</p>
<p>Next tutorial, the fun part, the AJAX!</p>
]]></description>
			<content:encoded><![CDATA[<p>Heres Part 2 of the jQuery AJAX login tutorial. If you haven&#8217;t already, i suggest you read part 1 located <a href="http://www.query7.com/jquery-ajax-login-series-pt1/">here</a>.</p>
<p>We are going to start writing the PHP code to process the form. This is fairly basic stuff, using <em>$_POST</em> to get the values from the form, then checking them against pre-assigned values, if they match, then echo approved, if they don&#8217;t then echo denied.</p>
<pre lang="php"><?php

if($_POST['submit']){

$username = $_POST['username'];
$password = $_POST['password'];

// Here you would put your validation, checking existing database records.

if($username == panzer &#038;&#038; $password == query7){

echo 'Logged in';

//Insert your cookie setting code here

} else {

echo 'Denied';

}

} else {

echo "Form not submitted";

}
?></pre>
<p>So at the end of this stage, you will have an HTML form set up and this PHP file. You can enter the username Panzer and the password of query7 into the form and it will return Logged in.</p>
<p>Next tutorial, the fun part, the AJAX!</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/jquery-ajax-tutorial-pt2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AJAX Series Coming Soon!</title>
		<link>http://query7.com/ajax-series-coming-soon</link>
		<comments>http://query7.com/ajax-series-coming-soon#comments</comments>
		<pubDate>Fri, 09 May 2008 03:50:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://www.query7.com/?p=48</guid>
		<description><![CDATA[<p>Hey guys, just thought i&#8217;d post a little interim post (as such). Im in the process of making a 4 part tutorial series on using jQuery&#8217;s AJAX. Its a &#8220;case study&#8221; where i/we will make a basic login form with a PHP backend and then use jQuery to make the login seemless. Eg. you put your username/password in the form and click the login button the page doesn&#8217;t reload but it will tell you whether its the correct user/pass , in which case a cookie is set, or if its bad info.</p>
<p>It might take a little while to finish up so i might not be posting much over the next week (sorry) but it will be worth it in the end.</p>
]]></description>
			<content:encoded><![CDATA[<p>Hey guys, just thought i&#8217;d post a little interim post (as such). Im in the process of making a 4 part tutorial series on using jQuery&#8217;s AJAX. Its a &#8220;case study&#8221; where i/we will make a basic login form with a PHP backend and then use jQuery to make the login seemless. Eg. you put your username/password in the form and click the login button the page doesn&#8217;t reload but it will tell you whether its the correct user/pass , in which case a cookie is set, or if its bad info.</p>
<p>It might take a little while to finish up so i might not be posting much over the next week (sorry) but it will be worth it in the end.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/ajax-series-coming-soon/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

