<?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>Surya's blog &#187; AJAX</title>
	<atom:link href="http://www.hakc.net/category/asynchronous-javascript-and-xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hakc.net</link>
	<description></description>
	<lastBuildDate>Thu, 30 Dec 2010 03:03:50 +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>AJAX Contact Form with captcha</title>
		<link>http://www.hakc.net/2008/04/06/ajax-contact-form-with-captcha/</link>
		<comments>http://www.hakc.net/2008/04/06/ajax-contact-form-with-captcha/#comments</comments>
		<pubDate>Sun, 06 Apr 2008 21:18:04 +0000</pubDate>
		<dc:creator>Surya</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[contact]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://www.hakc.net/?p=26</guid>
		<description><![CDATA[Here it is, an AJAX&#8217;d contact form with a captcha. I had an idea to code this about a week ago and thought would be a tough job to do but it wasn&#8217;t that tough to code when I started doing it. The only place where I had to spend a lot of time was, [...]]]></description>
			<content:encoded><![CDATA[<p>Here it is, an AJAX&#8217;d contact form with a captcha. I had an idea to code this about a week ago and thought would be a tough job to do but it wasn&#8217;t that tough to code when I started doing it. The only place where I had to spend a lot of time was, pondering how to pass the value from the &#8216;textarea&#8217; to the PHP preserving the line breaks. After googling for about an hour and reading different articles I finally got what was required, I just had to escape(): the variable before sending it to the PHP script.</p>
<p>On a positive note, I didn&#8217;t really have any problem with running this script on IE (I usually have to break my head over this matter). To prelude its features, I guess it does everything you&#8217;d normally except a contact form to do. It sanitizes all the variables, checks for the Email structure and disables the submit button once the email is sent to prevent mass emails. I would like to thank SecondVersion and Psyrens for the PHP backend &amp; ajax captcha respectively. As usual I&#8217;m lazy to provide a detailed documentation about it and would *make sure* that I write one in the future. But the whole script isn&#8217;t obfuscated at all, you&#8217;d just have to edit some constants and woo! it&#8217;s done.</p>
<p>I&#8217;m currently working on integrating this script as a wordpress plugin. Please let me know any bugs/commments/feedback by commenting below or contacting me. Show-off your own modified version of this script here <img src='http://www.hakc.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Script Demo : ~Snipped temporarily~<a href="http://hakc.net/ajax-contact-form-captcha-demo/" target="_blank"></a></p>
<p>Script Download : <a href="http://hakc.net/ajax-contact-form-captcha-demo/ajax-contact-form-hakc.net.zip" target="_blank">http://hakc.net/&#8230;./&#8230;.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hakc.net/2008/04/06/ajax-contact-form-with-captcha/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>AJAX Password Strength</title>
		<link>http://www.hakc.net/2007/04/06/ajax-password-strength/</link>
		<comments>http://www.hakc.net/2007/04/06/ajax-password-strength/#comments</comments>
		<pubDate>Fri, 06 Apr 2007 15:46:45 +0000</pubDate>
		<dc:creator>Surya</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.hakc.net/2007/04/06/ajax-password-strength/</guid>
		<description><![CDATA[Follow this URL : http://www.hakc.net/scripts/]]></description>
			<content:encoded><![CDATA[<p>Follow this URL :</p>
<p><a href="http://www.hakc.net/scripts/">http://www.hakc.net/scripts/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hakc.net/2007/04/06/ajax-password-strength/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Ajax-In-Ajax</title>
		<link>http://www.hakc.net/2007/03/01/ajax-in-ajax/</link>
		<comments>http://www.hakc.net/2007/03/01/ajax-in-ajax/#comments</comments>
		<pubDate>Thu, 01 Mar 2007 10:57:22 +0000</pubDate>
		<dc:creator>Surya</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.hakc.net/2007/03/01/ajax-in-ajax/</guid>
		<description><![CDATA[Someone at Digitalpoint asked me on how to have ajax inside ajax, like how to process a form with ajax which is already processed by ajax. It&#8217;s pretty simple first a file &#8220;POSTS&#8221; content into a php file which is received by ajax, this php file which receives the data has another form inside it [...]]]></description>
			<content:encoded><![CDATA[<p>Someone at Digitalpoint asked me on how to have ajax inside ajax, like how to process a form with ajax which is already processed by ajax. </p>
<p>It&#8217;s pretty simple first a file &#8220;POSTS&#8221; content into a php file which is received by ajax, this php file which receives the data has another form inside it which is too processed with ajax.  I&#8217;ve written the code for it and made the demo up here with download.</p>
<p>Read on more for Download / Demo link.</p>
<p><span id="more-12"></span></p>
<p><a href="http://hakc.net/ajax-in-ajax/" target="_blank">Demo here</a></p>
<p><a href="http://hakc.net/ajax-in-ajax/ajax-in-ajax.zip" target="_blank">Download Here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hakc.net/2007/03/01/ajax-in-ajax/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The &#8220;Hello World&#8221; AJAX script</title>
		<link>http://www.hakc.net/2007/02/15/the-hello-world-ajax-script/</link>
		<comments>http://www.hakc.net/2007/02/15/the-hello-world-ajax-script/#comments</comments>
		<pubDate>Thu, 15 Feb 2007 17:36:16 +0000</pubDate>
		<dc:creator>Surya</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.hakc.net/2007/02/15/the-hello-world-ajax-script/</guid>
		<description><![CDATA[I just made this quick ajax tutorial for people who&#8217;re starting out there and want to learn AJAX. The following tutorial will teach: how to submit a simple form through php and get the stuff printed out by using AJAX. The first sect will be plain simple to just print a input string and I&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>I just made this quick ajax tutorial for people who&#8217;re starting out there and want to learn AJAX. The following tutorial will teach: how to submit a simple form through php and get the stuff printed out by using AJAX. The first sect will be plain simple to just print a input string and I&#8217;ll add getting some dynamic content after it.</p>
<p>So let&#8217;s get started.<br />
Most of you may have a local server at your PC or a remote hosting; however remember there are no special requirements for this tutorial. All you need is a web server with PHP. If you&#8217;re right starting away you can install <a href="http://www.apachefriends.org/en/xampp.html" target="_blank">XAMPP</a> which will install all default modules on your PC directly.</p>
<p>More after the break.</p>
<p><span id="more-11"></span><br />
For the first part we&#8217;ll do our job using two files,</p>
<blockquote><p>1) Index.php</p>
<p>2) ajax.js (The AJAX framework)</p>
<p>3) Style.css (stylesheet)</p>
<p>4) form.php (To process the submitted data)</p></blockquote>
<p>So let&#8217;s first get started with ajax.js, I&#8217;ll explain this particular framework part by part.</p>
<p>We create a new file name &#8220;ajax&#8221; with &#8220;.js&#8221; extension.</p>
<p>Open up the file in your favourite text editor and follow the instructions that follow.<br />
We first create 4 new variables -&gt;</p>
<blockquote><p>var xml = makeXML();<br />
var form;<br />
var loading;<br />
var results;</p></blockquote>
<p><strong>xml &#8211; for creating the xml request,<br />
form &#8211; which gives the name of the form we&#8217;re going to use,<br />
loading &#8211; The div tag where the &#8220;loading&#8221; message will appear.<br />
results &#8211; The div tag where the output from the server will be shown.</strong></p>
<p>Now let&#8217;s create a XMLHttpRequest object depending on the browser the user uses. Remember Firefox owns the world! So let&#8217;s add some couple of more lines to the code.. I&#8217;ll be explaining each part by adding the comment tags corresponding to the respective lines.</p>
<blockquote><p>function makeXML () {<br />
if (typeof XMLHttpRequest == &#8216;undefined&#8217;) { // CHECK FOR IE<br />
objects = Array(<br />
&#8216;Microsoft.XmlHttp&#8217;,<br />
&#8216;MSXML2.XmlHttp&#8217;,<br />
&#8216;MSXML2.XmlHttp.3.0&#8242;,<br />
&#8216;MSXML2.XmlHttp.4.0&#8242;,<br />
&#8216;MSXML2.XmlHttp.5.0&#8242;<br />
);<br />
for (i = 0; i &lt; objects.length; i++) {<br />
try {<br />
return new ActiveXObject(objects[i]); // CREATE ACTIVEX IF IE<br />
} catch (e) {}<br />
}<br />
} else { // Else if other browser create their respective request.<br />
return new XMLHttpRequest();<br />
}<br />
}</p></blockquote>
<p>Now get&#8217;s the real part which has the vital information, but before that let&#8217;s see how does the current &#8220;ajax.js&#8221; file looks so far:</p>
<blockquote><p>var xml = makeXML();<br />
var form;<br />
var loading;<br />
var results;<br />
function makeXML () {<br />
if (typeof XMLHttpRequest == &#8216;undefined&#8217;) {<br />
objects = Array(<br />
&#8216;Microsoft.XmlHttp&#8217;,<br />
&#8216;MSXML2.XmlHttp&#8217;,<br />
&#8216;MSXML2.XmlHttp.3.0&#8242;,<br />
&#8216;MSXML2.XmlHttp.4.0&#8242;,<br />
&#8216;MSXML2.XmlHttp.5.0&#8242;<br />
);<br />
for (i = 0; i &lt; objects.length; i++) {<br />
try {<br />
return new ActiveXObject(objects[i]);<br />
} catch (e) {}<br />
}<br />
} else {<br />
return new XMLHttpRequest();<br />
}<br />
}</p></blockquote>
<p>Okay, now We&#8217;ll be adding some more lines, this time I&#8217;ll break each of them so that you understand clearly.</p>
<blockquote><p> window.onload = function () {<br />
form = document.getElementById(&#8216;form&#8217;);<br />
loading = document.getElementById(&#8216;loading&#8217;);<br />
results = document.getElementById(&#8216;results&#8217;);
</p></blockquote>
<p>Now let&#8217;s break it in parts and see how it works.</p>
<p><code>window.onload = function () {</code> -&gt; <strong>We load a function as soon as the page is called upon.<br />
</strong><br />
<code>form = document.getElementById('form');<br />
loading = document.getElementById('loading');<br />
results = document.getElementById('results');</code><br />
<strong>Remember the variables we declared at start? Now it&#8217;s time to give them some values</strong>.<br />
we give form = document.getElementById(&#8216;form&#8217;); which means to get the element names &#8220;form&#8221;.</p>
<p>Similarly loading and results are too stored.<br />
Now let&#8217;s look further more.</p>
<blockquote><p>form.onsubmit = function () {<br />
results.style.display = &#8216;none&#8217;; // Set the Display STYLE of results to &#8220;none&#8221;<br />
results.innerHTML = &#8221;; // Fill up results with NULL (Nothing)<br />
loading.style.display = &#8216;inline&#8217;; // Set the Display STYLE of loading to show up, so that whenever the user clicks a loading text/image shows up.</p></blockquote>
<p>form.onsubmit = function () { -&gt;   <strong>When the form is submitted perform the function</strong><br />
results.style.display = &#8216;none&#8217;; -&gt; <strong>Set the Display STYLE of results to &#8220;none&#8221;</strong><br />
results.innerHTML = &#8221;; -&gt; <strong>Fill up results with NULL (Nothing)</strong></p>
<p>Now let&#8217;s proceed further.</p>
<blockquote><p>xml.open(&#8216;get&#8217;, &#8216;./form.php?name=&#8217; + escape(this.name.value))</p></blockquote>
<p><strong>open the file through xml using header &#8220;get&#8221; that is form.php and we pass on the variables asked by the php file.</strong></p>
<p><strong>Observe carefully we call a file <strong>form.php</strong> which wants the data for it&#8217;s variable &#8220;<strong>name</strong>&#8220;.<br />
We assign the value to the variable as &#8220;<strong>this.name.value</strong>&#8220;, notice something there? The part in the middle &#8220;<strong>name</strong>&#8221; tells the javascript to give the value of form name which has &#8216;name&#8217;.</strong></p>
<p>You maybe puzzled there, let me explain in plain words we give form.php to assign a value to the variable &#8220;name&#8221; with the form which has the id as &#8220;name&#8221; this may still be confusing but note this It&#8217;ll be cleared soon when we start the php form.</p>
<p>Okay, let&#8217;s go ahead and see the next few lines.</p>
<blockquote><p>xml.onreadystatechange = function () {<br />
if (xml.readyState == 4 &amp;&amp; xml.status == 200) {</p></blockquote>
<p>xml.onreadystatechange = function () { -&gt; <strong>when the data is received perform the further action.</strong></p>
<p>if (xml.readyState == 4 &amp;&amp; xml.status == 200) { -&gt; <strong>When ReadyState property is 4 and Status is 200, do the next stuff inside the loop.</strong></p>
<p>Now you may ask me about these properties let&#8217;s see -&gt;<br />
<a href="http://www.w3schools.com/ajax/ajax_xmlhttprequest.asp">Check W3&#8242;s clear explanation on these AJAX properties</a></p>
<p>Now when we have the positive response from the server let&#8217;s perform the main function.</p>
<blockquote><p>results.style.display = &#8216;block&#8217;;<br />
results.innerHTML = xml.responseText;<br />
loading.style.display = &#8216;none&#8217;;<br />
}<br />
}</p></blockquote>
<p>Let&#8217;s break &#8216;em too<br />
results.style.display = &#8216;block&#8217;; -&gt; <strong>Open up the results block</strong><br />
results.innerHTML = xml.responseText; -&gt; <strong>Paste the SERVER&#8217;s response in the div tag results.</strong><br />
loading.style.display = &#8216;none&#8217;; -&gt; <strong>Remember we set a loading tag on to display? Now when we got the data let&#8217;s switch of the loading stuff.</strong></p>
<p>Now the last part of this nasty javascript&#8230;</p>
<blockquote><p>xml.send(null); // if no data is sent, replace the results with NULL.<br />
return false;<br />
}<br />
} // Loop closed.</p></blockquote>
<p>OK <strong>AJAX.JS</strong> is complete, the complete code follows:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>http://hakc.net/ajax/ajax.js</p>
<p>There you go, hope I didn&#8217;t mess it up yet.<br />
Now let&#8217;s move over to the main PHP Stuff.</p>
<p>http://www.hakc.net/ajax/index.txt (Remember to make it &#8216;.php&#8217;)</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Now you maybe buzzing around that won&#8217;t the loading page displayed regardless of the user submits the form or not right ? That&#8217;s why we have linked a <strong>stylesheet</strong> into it. We&#8217;ll define a property to the &#8220;loading&#8221; tag which will hide the loading tag so that it&#8217;s not executed when the page is displayed, instead when the user submits the form the <strong>javascript <em>overrides</em> the stylesheet property</strong> and displays it again.</p>
<p>Lets look over at the stylesheet.css</p>
<blockquote><p>#loading {<br />
display: none; // It&#8217;s pretty simple it just hides it!<br />
}</p></blockquote>
<p>Here is the stylesheet, again remember to change the extension to <strong>css</strong>.</p>
<p>http://www.hakc.net/ajax/stylesheet.txt</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Now last but not the least let&#8217;s go with the last php file which processes the data and prints us out!</p>
<p>This is pretty simple!</p>
<blockquote><p> &lt;?php<br />
$printdata=$_GET['name']; // Get the &#8220;name&#8221; data and store it in &#8220;printdata&#8221;.<br />
echo $printdata; // print the stuff stored in printdata.<br />
?&gt;</p></blockquote>
<p>Ok so there it goes the final stuff, the php code. (PS again change the ext to <strong>php</strong>)</p>
<p>http://www.hakc.net/ajax/form.txt</p>
<p>That&#8217;s about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hakc.net/2007/02/15/the-hello-world-ajax-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

