<?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>use strict ;#) &#187; Ajax</title>
	<atom:link href="http://usestrict.net/category/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://usestrict.net</link>
	<description>Vinny&#039;s Technical Corner</description>
	<lastBuildDate>Wed, 14 Jul 2010 20:21:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Introduction to Ajax</title>
		<link>http://usestrict.net/2009/08/24/introduction-to-ajax/</link>
		<comments>http://usestrict.net/2009/08/24/introduction-to-ajax/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 21:56:08 +0000</pubDate>
		<dc:creator>Vinny</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[how to]]></category>

		<guid isPermaLink="false">http://usestrict.net/?p=840</guid>
		<description><![CDATA[Introduction to Ajax, Ajax how-to]]></description>
			<content:encoded><![CDATA[<p>In this article, I provide an explanation of Ajax with a historical introduction. If you are eager to start seeing the code, please scroll down.</p>
<p>&nbsp;</p>
<h3>What’s Ajax?</h3>
<p>&nbsp;</p>
<p>Ajax stands for <em>Asynchronous Javascript And XML</em>. It’s a way to call back-end scripts asynchronously – that is, without impacting user experience/flow. Basically, you don't even see the cursor become an hourglass or whatever other "waiting/processing" icon your system uses. It's not a language, but a technique. As for back-end scripts, you can use whatever you feel more comfortable with: PHP, Perl, Java, JSP, Shell, C, etc. The way to choose which technology to use as back-end is not outside the scope of this article.</p>
<p>&nbsp;</p>
<h3>Historical approach for calling back-end apps</h3>
<p>&nbsp;</p>
<p>Throughout web-development history, the very first way used to achieve back-end processing followed by front-end display was to create a form and set the back-end script as the action to that form. Upon submission, the form fields would be sent to the back-end script as a series of special environment variables, which would then be handled by the programmed logic. The back-end output would be displayed on the screen (either the same page/frame or a different page/frame, depending on the target attribute of the form).</p>
<p>The catch 22 of this approach is that if you want to present another form after processing, that form must be produced by the back-end script, which leads to maintenance mayhem – to add or remove a field, you have to do so in both the original HTML and in the HTML of the back-end script.</p>
<p><span id="more-840"></span></p>
<p>&nbsp;</p>
<h3>Hidden IFRAMES and Javascript to the rescue</h3>
<p>&nbsp;</p>
<p>The natural evolution of the regular form submission was to avoid having to generate HTML from the back-end script. A technique that I eventually came up with (had never seen it before, but it was probably already out there) prior to adhering to Ajax was using a hidden IFRAME as target to a simple form containing an <em>action_cd</em> field and a <em>data</em> field. There would not be a regular submit button, but a set of input elements with <em>onclick</em> or <em>onchange</em> events and a regular (non-submit) button at the end. </p>
<p>In this approach, Javascript did all the work – when the user clicked the pseudo-submit button, an <em>onclick</em> event would read all the input fields and join them like a regular HTTP query (<code>field1=val1&#038;field2=val2</code>…). The <em>action_cd</em> value would be dynamically evaluated and the back-end script would receive the data string and action code and process it. Javascript would perform the submission when, say, a value of a drop-down field was selected, and the output would be a series of dynamically generated Javascript commands inside the IFRAME. Those commands would manipulate the user’s form (e.g. Auto-populate a "state" drop-down after selecting a "country" value). </p>
<p>Although this approach successfully handled the no-longer-need to submit and reload a form, it still had 2 main downsides: generating and maintaining Javascript code is not a simple task (especially due to having to escape quotes), and the whole procedure was still synchronous – you could see the hourglass, browser process bars, clicking sounds (IE), etc. It's much better user experience, but still not the real deal, seamless/transparent back-end processing.</p>
<p>&nbsp;</p>
<h3>The XmlHttpRequest object</h3>
<p>&nbsp;</p>
<p>Javascript back-end calls are made possible thanks to the <em>XmlHttpRequest</em> object that most modern browsers now support. For IE 6 and older, it is done through an ActiveXObject. </p>
<p>&nbsp;</p>
<h3>Javascript code to initialize Ajax object</h3>
<p>&nbsp;</p>
<pre class="brush:javascript">

var xmlHttp; // global variable. It’s important for later on

function GetXmlHttpObject(){

      if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
      }

      if (window.ActiveXObject){
        // code for IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
      return null;
}
</pre>
<p>It's important to have a global variable in which to assign the XMLHttpRequest object, since this technique has its shortcomings when dealing with passing variables around. We'll understand that better shortly. The function checks for the existence of <strong>window.XMLHttpRequest</strong> which is used in IE7 (finally, it complies to standards!), Firefox, and other non IE browsers, and checks for <strong>window.ActiveXObject</strong> existence for IE6 and 5. I’m not sure if this works on IE4 – it probably does not, but hopefully IE4 is already in extinction. If neither checks work, it returns null, which will be handled in the function calling the XMLHttpObject.</p>
<p>&nbsp;</p>
<h3>Making Synchronous Ajax calls (GET method)</h3>
<p>&nbsp;</p>
<p>Although the hype of Ajax is due to the "Asynchronosity" of the technique, it is also capable of making synchronous calls. Synchronous calls are important in cases where you don't want to allow the user to do something while the back-end is checking a previous action, but also don't want to have to submit the whole form.</p>
<pre class="brush:javascript">

function synch_call() {

      // initialize Ajax object
      var xmlHttp = GetXmlHttpObject(); 

      // Set the URL to your backend script with query vars
      var url = “/url/to/your/backend/script?with=var1&#038;and=var2”;

      // Synchronous call
      xmlHttp.open("GET",url,false); // "false" means asynchronous = false
      xmlHttp.send(null);

      // the code above does the back-end call. Now we handle the response
      // this function continues further down in the tutorial

}
</pre>
<p>Ajax calls can be done using GET or POST methods. I recommend GET methods for small queries, POST for large ones. There used to be a limit of 255 characters on URL fields – not sure if a) this is still true; b) this could apply to these Ajax techniques.</p>
<p>The call to the back-end is done by 2 commands: <strong>xmlHttp.open(Method,url,async)</strong>, and the <strong>xmlHttp.send(null)</strong> calls. For POST method, this is a little different, so we’ll stick to GET calls for the time being.</p>
<p>&nbsp;</p>
<h3>Handling back-end reply</h3>
<p>&nbsp;</p>
<p><em>Asynchronous Javascript And XML</em> isn't the perfect name for Ajax. It should be more like Aja<strong>R</strong>, where R stands for Reply. The reason is because the reply can be either an XML structure or a plain text. We use <strong>xmlHttp.responseXML.documentElement</strong> if we’re handling XML, or a plain <strong>xmlHttp.responseText</strong> for plain text. Actually, we can use the latter for XML as well, especially when debugging the code (when you want to pop up the XML reply).</p>
<p>We use a try/catch block to capture any errors:</p>
<pre class="brush:javascript">
function synch_call() {

      // initialize Ajax object
      var xmlHttp = GetXmlHttpObject(); 

      // Set the URL to your backend script with query vars
      var url = “/url/to/your/backend/script?with=var1&#038;and=var2”;

      // Synchronous call

      xmlHttp.open("GET",url,false); // “false” means asynchronous = false
      xmlHttp.send(null);

      // the code above does the back-end call. Now we handle the response
      try {            

            alert("Ajax Response: \n"+xmlHttp.responseText); // Just pop-up the reply
            return false;
      }
      catch(e) {
            alert(e); // if error, show it as a pop-up
            return false;
      }
}
</pre>
<p>&nbsp;</p>
<p>To handle the  reply as XML, you need to a) make sure your back-end script outputs an XML structure, and b), replace xmlHttp.reponseText for xmlHttp.responseXML.documentElement.</p>
<p>&nbsp;</p>
<pre class="brush:javascript">
// Just the try/catch block changed        

       try {
              data = xmlHttp.responseXML.documentElement;
        }
        catch(e) {
               alert(e);
               return false;
        }
</pre>
<p>The <code>data</code> variable now holds a DOM object of the XML structure. To access its elements, we use DOM functions. </p>
<p>Example XML structure:</p>
<pre class="brush:xml">
&lt;OUT&gt;
      &lt;STATUS&gt;Success&lt;/STATUS&gt;
      &lt;MSG type="some_type"&gt;This is a test message&lt;/MSG&gt;
&lt;/OUT&gt;
</pre>
<p>Accessing Example XML through DOM:</p>
<pre class="brush:javascript">

      // gets the Success text
      var msg_status = data.getElementsByTagName(‘STATUS’)[0].childNodes[0].nodeValue;

      // Assign MSG object to msg variable
      var msg = data.getElementsByTagName(‘MSG’)[0]; 

      // gets the attribute “type”
      var msg_type = msg.getAttribute(‘type’); 

      // gets the text inside the MSG node
      var msg_text = msg.childNodes[0].nodeValue;
</pre>
<p>&nbsp;</p>
<h3>Putting it all together</h3>
<p>&nbsp;</p>
<pre class="brush:javascript">
function synch_call() {

      // initialize Ajax object
      var xmlHttp = GetXmlHttpObject(); 

      // Set the URL to your backend script with query vars
      var url = “/url/to/your/backend/script?with=var1&#038;and=var2”; 

      // Synchronous call
      xmlHttp.open("GET",url,false); // "false" means asynchronous = false
      xmlHttp.send(null);

      // the code above does the back-end call. Now we handle the response

      try {
            data = xmlHttp.responseXML.documentElement;
       }
       catch(e) {
             alert(e);
             return false;
       }

      // gets the Success text
      var msg_status = data.getElementsByTagName(‘STATUS’)[0].childNodes[0].nodeValue; 

      // Assign MSG object to msg variable
      var msg = data.getElementsByTagName(‘MSG’)[0]; 

      // gets the attribute “type”
      var msg_type = msg.getAttribute(‘type’); 

      // gets the text inside the MSG node
      var msg_text = msg.childNodes[0].nodeValue;
      alert("Got the following backend reply: " + msg_status + "\n" + msg + "\n" + msg_type + "\n" + msg_text);

      return true;
}
</pre>
<p>&nbsp;</p>
<h3>Making Asynchronous Ajax calls (GET method)</h3>
<p>&nbsp;</p>
<p>We saw on page 2 that what controls synchronicity of the Ajax call is the true/false value in the <code>open()</code> command. However, we also need changes in the way we handle the reply. We do that by setting <strong><em>onreadystatechange</em></strong> property on the xmlHttp object.</p>
<p> OnReadyStateChange should be a function that will check the <em><strong>readyState</strong></em> attribute of the xmlHttp object.</p>
<p>&nbsp;</p>
<h3>Understanding readyState</h3>
<p>&nbsp;</p>
<p>readyStates are the way Javascript controls what stage of the process the call is in. It ranges from 0 to 4, where 4 is the completed reply from the back-end script. We normally only care about readyState == 4. Here are the codes and meaning:</p>
<table>
<tr>
<td><strong>Value</strong></td>
<td><strong>State</strong></td>
</tr>
<tr>
<td>0</td>
<td>Uninitialized</td>
</tr>
<tr>
<td>1</td>
<td>Loading</td>
</tr>
<tr>
<td>2</td>
<td>Loaded</td>
</tr>
<tr>
<td>3</td>
<td>Interactive</td>
</tr>
<tr>
<td>4</td>
<td>Complete</td>
</tr>
</table>
<p>&nbsp;</p>
<h3>Setting onreadystatechange</h3>
<p>&nbsp;</p>
<p><code>onreadystatechange</code> can be assigned a anonymous <code>function() {  }</code> block, or a named function. Just be careful with function parameters – to this day, I have not been able to pass any parameters to the functions set to <code>onreadystatechange</code>. Hence the need for some global variables in play.</p>
<p>Let's copy over our <code>sync_call()</code> function and make it <code>Async_call()</code></p>
<pre class="brush:javascript">
function Asynch_call() {

      // initialize Ajax object
      var xmlHttp = GetXmlHttpObject(); 

      // Set the URL to your backend script with query vars
      var url = “/url/to/your/backend/script?with=var1&#038;and=var2”;

      // onreadystatechange must be set BEFORE making the call

      // it takes the response handling code that we had in the sync_call() previously
      xmlHttp.onreadystatechange = function() {

            if (xmlHttp.readyState == 4) { // Complete

                  // Now we handle the response within the onreadystatechange
                  try {
                        data = xmlHttp.responseXML.documentElement;
                  }
                  catch(e) {
                        alert(e);
                        return false;
                  }

                  // gets the Success text
                  var msg_status = data.getElementsByTagName(‘STATUS’)[0].childNodes[0].nodeValue; 

                  // Assign MSG object to msg variable
                  var msg = data.getElementsByTagName(‘MSG’)[0]; 

                  // gets the attribute "type"
                  var msg_type = msg.getAttribute('type'); 

                  // gets the text inside the MSG node
                  var msg_text = msg.childNodes[0].nodeValue;

                  alert("Got the following backend reply: " + msg_status + "\n" + msg + "\n" + msg_type + "\n" + msg_text);
                  return true;
            }

      }; // don’t forget the ';' at the end of the function() {} block!!

      // Asynchronous call
      xmlHttp.open("GET",url,true); // 'true' means asynchronous = true
      xmlHttp.send(null);
}
</pre>
<p>&nbsp;</p>
<p>As mentioned before, you can separate the anonymous function assignment into a named function. The good side of this is that your functions get more manageable, but the downside is that you might need global variables in order to share values between the main function and the <code>onreadystatechange,/code> function.</p>
<p>&nbsp;</p>
<pre class="brush:javascript">
function Asynch_call() {

      // initialize Ajax object
      var xmlHttp = GetXmlHttpObject(); 

      // Set the URL to your backend script with query vars
      var url = “/url/to/your/backend/script?with=var1&#038;and=var2”; 

      // onreadystatechange must be set BEFORE making the call

      // it takes the response handling code that we had in the sync_call previously
      xmlHttp.onreadystatechange = handlerfunction; // See separate function below    

      // Asynchronous call
      xmlHttp.open("GET",url,true); // “true” means asynchronous = true
      xmlHttp.send(null);
}

function handlerfunction() {

      if (xmlHttp.readyState == 4) { // Complete – must be global xmlHttp variable

            // Now we handle the response within the onreadystatechange
            try {
                  data = xmlHttp.responseXML.documentElement;
            }
            catch(e) {
                  alert(e);
                  return false;
            }

             // gets the Success text
            var msg_status = data.getElementsByTagName(‘STATUS’)[0].childNodes[0].nodeValue; 

            // Assign MSG object to msg variable
            var msg = data.getElementsByTagName(‘MSG’)[0]; 

            // gets the attribute “type”
            var msg_type = msg.getAttribute(‘type’); 

            // gets the text inside the MSG node
            var msg_text = msg.childNodes[0].nodeValue;

            alert("Got the following back-end reply: " + msg_status + "\n" + msg + "\n" + msg_type + "\n" + msg_text);
            return true;

      }
}
</pre>
<p>&nbsp;</p>
<h3>Parsing forms to create the GET/POST strings</h3>
<p>&nbsp;</p>
<p>Since we are not submitting the form with the usual submit button, we have to handle building the queries ourselves. I came up with a function that mimics the way browsers handle function calls.</p>
<pre class="brush:javascript">
function build_post_string(frm) {

      var str;
      var poststr_array = [];

      if (!frm.id) {
            // assume it's a string. get the form object
            frm = document.getElementById(frm);
      }

      for (i=0;i&lt;frm.elements.length;i++){

            var elem = frm.elements[i];

            if (!elem.id) {
                  // skip any fields that don't have IDs
                  continue;
            }

            if (elem.type == 'radio' || elem.type == 'checkbox') {

                  // only grab radio buttons and checkboxes that are checked
                  if (!elem.checked) {
                        continue;
                  }

            }            

            // get select values
            if (elem.nodeName.match(/SELECT/i) &#038;& elem.multiple) {

                  var sel_array = [];

                  for (var o=0;o&lt;elem.options.length;o++) {

                        if (elem.options[o].selected) {
                              sel_array[sel_array.length] = elem.id+"="+elem.options[o].value;
                        }

                  }

                  var sel_str = sel_array.join('&#038;');

                  // build key/value pairs for SELECTs
                  poststr_array[poststr_array.length] = sel_str;
            }
            else if (elem.nodeName.match(/SELECT/i)) {
                  poststr_array[poststr_array.length] = elem.id+'='+elem.options[elem.selectedIndex].value;
            }
            else {
                  // build key/value pairs for everything else
                  poststr_array[poststr_array.length] = elem.id+"="+elem.value;
            }

      }

      // build and return str
      str = poststr_array.join("&#038;");
      return str;
}
</pre>
<p>This function takes a given form by ID and iterates through all of its elements. It is important that all fields you want in the query have an ID attribute. Otherwise they will be skipped. <strong>The return from this function can be used for both GET and POST requests.</strong></p>
<p>&nbsp;</p>
<h3>Using POST method for Ajax calls</h3>
<p>&nbsp;</p>
<p>So far we saw that making GET calls is pretty straight-forward. POST calls are different in the way that they are not put in the HTTP Header, but rather in a separate packet. In order to do that, we need to set a few header variables:</p>
<pre class="brush:javascript">
function Asynch_call_with_post() {

      // initialize Ajax object
      var xmlHttp = GetXmlHttpObject(); 

      // Set the URL to your backend script with query vars
      var post_str = build_post_string(‘my_form’); 

      var url = “/url/to/your/backend/script?” + post_str;

      // onreadystatechange must be set BEFORE making the call
      // it takes the response handling code that we had in the sync_call previously
      xmlHttp.onreadystatechange = function() {

            if (xmlHttp.readyState == 4) { // Complete

                   // Now we handle the response within the onreadystatechange
                   try {
                         data = xmlHttp.responseXML.documentElement;
                    }
                    catch(e) {
                         alert(e);
                         return false;
                    }

                     // gets the Success text
                     var msg_status = data.getElementsByTagName(‘STATUS’)[0].childNodes[0].nodeValue; 

                      // Assign MSG object to msg variable
                     var msg = data.getElementsByTagName(‘MSG’)[0]; 

                     // gets the attribute “type”
                     var msg_type = msg.getAttribute(‘type’); 

                     // gets the text inside the MSG node
                     var msg_text = msg.childNodes[0].nodeValue;
                     alert("Got the following backend reply: " + msg_status + "\n" + msg + "\n" + msg_type + "\n" + msg_text);
                     return true;
               }

        }; // don't forget the ';' at the end of the function() {} block

        // Asynchronous call
        xmlHttp.open('POST',url, true); // Replace "GET" with "POST"

        // Set headers
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", url.length);
        xmlHttp.setRequestHeader("Connection", "close");

        // Send the packet. Note that it’s no longer null as parameter to send
        xmlHttp.send(url);
}
</pre>
<p>&nbsp;</p>
<h3>Showing/Hiding "Processing…" messages</h3>
<p>&nbsp;</p>
<p>Since Ajax in Asynchronous mode is 100% transparent to the user, it is necessary to handle our own messages asking the user to wait until processing finishes. The simplest way to do this is by using a <code>DIV</code> element with initial display property set as none, or visibility set as hidden (the difference is that <code>visibility="hidden"</code> makes the element still occupy its space in the page, whereas <code>display="none"</code> effectively removes the element from the page and the space that it occupied).</p>
<p>Typically, I include code to show the element in the Ajax function, and code to hide it again in the <em>onreadystatechange</em> function (where readyState == 4). </p>
<pre class="brush:javascript">
        document.getElementById(‘wait_image’).display = ‘block’;
        document.getElementById(‘wait_image’).display = ‘none’;
</pre>
<p>&nbsp;</p>
<h3>Third-Party AJAX Libraries</h3>
<p>&nbsp;</p>
<p>There are several Ajax in a box libraries out there, but I am not comfortable with using them for company applications. The reason being is that Ajax is very powerful and can very well make calls to the maintainer's website to steal/capture sensitive information.  </p>
<p>Google provides Java code that generates Ajax during build – that is a typical example of us not being able to control Ajax code generated. </p>
<p>&nbsp;</p>
<h3>Testing the back-end script</h3>
<p>&nbsp;</p>
<p>There are 2 simple ways of testing the back-end script. With PHP, you can access both GET and POST variables through the <code>$_REQUEST</code> array. Perl CGI doesn’t really care if it’s GET or POST. I don’t know how JSP can handle it. With this being said, I simply have the Ajax alert the URL variable and return false. I then copy the URL variable and paste it in another window to see the output.</p>
<p>I strongly recommend debugging with Firefox – it has a handy error console and also parses the output XML or complains if it’s not built right.</p>
<p>&nbsp;</p>
<h3>Keeping IE from crashing with the XMLs</h3>
<p>&nbsp;</p>
<p>I'm pretty sure that Microsoft IE developers have some satisfaction in making web developers go crazy. That's how I felt when I started working with XML and Ajax, and although my <a href="http://mywebchat.usestrict.net" target="_blank">app</a> was working fine in Firefox, it kept crashing bad in IE. After some googling, I found out that I needed to set some headers in order to keep IE from blowing up. I already had the <code>"Content-type: text/xml"</code> header in place, but it appears that IE needs some caching control and expiry headers as well.</p>
<p>This is what I use in PHP:</p>
<pre class="brush:php">
        header("Expires: Fri, 09 Jan 1981 05:00:00 GMT");
        header("Cache-Control: no-store, no-cache, must-revalidate");
        header("Cache-Control: post-check=0, pre-check=0", FALSE); // FALSE means add this Cache-Control line instead of replacing the previous one
        header("Pragma: no-cache");
        header("Content-type: text/xml");
</pre>
<p>In Perl, setting headers is simple: just <code>print</code> them before printing any content. When you're done printing all your headers, print an empty newline to indicate where the page content will go.</p>
<p>I hope you've enjoyed this tutorial. Feel free to paste comments regarding your experience and preferences.</p>
]]></content:encoded>
			<wfw:commentRss>http://usestrict.net/2009/08/24/introduction-to-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax: Form fields into URL query string</title>
		<link>http://usestrict.net/2009/07/31/ajax-form-fields-into-url-query-string/</link>
		<comments>http://usestrict.net/2009/07/31/ajax-form-fields-into-url-query-string/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 09:46:20 +0000</pubDate>
		<dc:creator>Vinny</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Query string]]></category>
		<category><![CDATA[URL Query]]></category>

		<guid isPermaLink="false">http://usestrict.net/?p=818</guid>
		<description><![CDATA[Javascript code to parse form fields into URL query string. To be used with Ajax sites.]]></description>
			<content:encoded><![CDATA[<p>Here's a quickie for you Ajax coders who need a function to parse your form fields into a URL query string. It handles input fields (text, hidden, whatever), radio and checkbox elements, and single/multiple select menus. Just make sure that all your form fields have IDs. <del>Multiple choice SELECTs get grouped by pipes (|).</del> <strong>Update:</strong>Modified multiple-choice SELECTs to work like real GETs.</p>
<pre class="brush:javascript">
function build_post_string(frm) {

	var poststr;
	var poststr_array = [];

	if (!frm.id) {
		// assume it's a string. get the form object
		frm = document.getElementById(frm);
	}

	for (i=0;i&lt;frm.elements.length;i++){

		var elem = frm.elements[i];

		if (!elem.id) {
			// skip any fields that don't have IDs
			continue;
		}

		if (elem.type == 'radio' || elem.type == 'checkbox') {
			// only grab radio buttons and checkboxes that are checked
			if (!elem.checked) {
				continue;
			}
		}

		// get select values
		if (elem.nodeName.match(/SELECT/i) &#038;& elem.multiple) {
			//var sel = elem;
			var sel_array = new Array();

			for (var o=0;o&lt;elem.options.length;o++) {

				if (elem.options[o].selected) {
					sel_array[sel_array.length] = elem.id+"="+elem.options[o].value;
				}
			}

			var sel_str = sel_array.join('&#038;');

			// build key/value pairs for SELECTs
			poststr_array[poststr_array.length] = sel_str;
		}
		else if (elem.nodeName.match(/SELECT/i)) {
			poststr_array[poststr_array.length] = elem.id+'='+elem.options[elem.selectedIndex].value;
		}
		else {
			// build key/value pairs for everything else
			poststr_array[poststr_array.length] = elem.id+"="+elem.value;
		}

	}

	// build poststr
	poststr = poststr_array.join("&#038;");
	return poststr;

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://usestrict.net/2009/07/31/ajax-form-fields-into-url-query-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Tech Jobs section</title>
		<link>http://usestrict.net/2009/06/13/new-perl-jobs-section/</link>
		<comments>http://usestrict.net/2009/06/13/new-perl-jobs-section/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 07:00:33 +0000</pubDate>
		<dc:creator>Vinny</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Jobs]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Perl Jobs]]></category>

		<guid isPermaLink="false">http://usestrict.net/?p=559</guid>
		<description><![CDATA[I've added a Tech Jobs page to the main pages section (right under the header) for those who are looking for jobs. Right now it only has the RSS from jobs.perl.org, but I intend to create a mash-up from several sites in the future. Update: Added craigslist.com search for Perl jobs in Canada (Vancouver only). [...]]]></description>
			<content:encoded><![CDATA[<p>I've added a <a href="/perl-jobs/" target="_blank">Tech Jobs</a> page to the main pages section (right under the header) for those who are looking for jobs. <del datetime="2009-06-08T12:27:50+00:00">Right now it only has the RSS from jobs.perl.org</del>, but I intend to create a mash-up from several sites <del datetime="2009-06-08T12:27:50+00:00">in the future</del>.</p>
<p><strong>Update:</strong> Added craigslist.com search for Perl jobs in Canada <del datetime="2009-06-09T13:53:18+00:00">(Vancouver only). Next is to add some fields which allow folks to select keywords and places</del> (Done! See update below).</p>
<p><strong>Update:</strong> The Feed fetcher now works with craigslist.com worldwide. You can also use search keys for feeds that accept them.</p>
<p><strong>Update (6/13/09):</strong> monster.com added with 192 countries (!!). Since some sources accept keywords and others don't, the form will now tell you so. Also, modified the form to allow blank keywords for some sources. The issue is that craigslist uses a totally separate query for blank keywords, and right now the fetcher doesn't handle alternate query strings per source. <strong>Total Sources: 4. Total feeds: 708.</strong></p>
<p>Good luck job-hunting!</p>
<p>Vinny.</p>
]]></content:encoded>
			<wfw:commentRss>http://usestrict.net/2009/06/13/new-perl-jobs-section/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax Eye Candy: Create &#8220;Wait&#8221; icons on the fly</title>
		<link>http://usestrict.net/2009/05/08/ajax-eye-candy-create-wait-icons-on-the-fly/</link>
		<comments>http://usestrict.net/2009/05/08/ajax-eye-candy-create-wait-icons-on-the-fly/#comments</comments>
		<pubDate>Fri, 08 May 2009 19:15:22 +0000</pubDate>
		<dc:creator>Vinny</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[gif]]></category>
		<category><![CDATA[wait icons]]></category>

		<guid isPermaLink="false">http://usestrict.net/?p=468</guid>
		<description><![CDATA[This is by far the coolest and handiest website I've come across in a very long time. Get your very own Wait icons for Ajax implementations on the fly. http://www.ajaxload.info It's not mine, and I don't know the author... but click an ad there if you like it. The guy deserves it.]]></description>
			<content:encoded><![CDATA[<p>This is by far the coolest and handiest website I've come across in a very long time. Get your very own Wait icons for Ajax implementations on the fly.</p>
<p><a href="http://www.ajaxload.info" target="_blank">http://www.ajaxload.info</a></p>
<p>It's not mine, and I don't know the author... but click an ad there if you like it. The guy deserves it.</p>
]]></content:encoded>
			<wfw:commentRss>http://usestrict.net/2009/05/08/ajax-eye-candy-create-wait-icons-on-the-fly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>myWebChat: IM with your site&#8217;s visitors</title>
		<link>http://usestrict.net/2009/03/11/mywebchat-im-with-your-sites-visitors/</link>
		<comments>http://usestrict.net/2009/03/11/mywebchat-im-with-your-sites-visitors/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 13:57:45 +0000</pubDate>
		<dc:creator>Vinny</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[myWebChat]]></category>
		<category><![CDATA[newbies]]></category>
		<category><![CDATA[chat]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[web chat]]></category>

		<guid isPermaLink="false">http://usestrict.net/?p=280</guid>
		<description><![CDATA[Info regarding new Web Chatting application which allows site owners to interact with their visitors in real time.]]></description>
			<content:encoded><![CDATA[<p>I once saw a comment on AlphaInventions saying that the user would find it very nice if they could know who was visiting their blog and could talk to them in real time.</p>
<p>That, along with the ChatterBox in <a href="http://www.perlmonks.org" target="_blank">Perlmonk</a>'s website gave me the idea:  why not build a ChatterBox-like application that bloggers could use as a widget and regular sites could have as a pop-up or as  an embedded frame/div?</p>
<p>I did some digging and all I could find were apps that needed installation or were built in heavy Java. So I started out on my own project, which I called myWebChat (because it was <em>my</em> Web Chat application, of course <img src='http://usestrict.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ).</p>
<p>Well, several weeks later (perhaps a few months with all the stuff I have going on), I am proud to announce <a href="http://mywebchat.usestrict.net" target="_blank">myWebChat version 0.2 and the hot-site</a>.</p>
<p>The funcionality is still pretty basic, but will allow you to talk to anyone who enters the chat with their username (no password required yet). It's like having an open chat room in your own website.</p>
<h3>What it is:</h3>
<ul>
<li><strong>It's a chat application</strong> that stays hosted on our servers, but <strong>shows on your website</strong> - you just need to add a snippet of code to your page.</li>
<li><strong>It's free</strong>: as in beer - you don't pay anything to use it on one domain. However, since I also need to pay my bills, I accept donations for the free version, which can also work as payment for the premium version. The main difference between the free and premium versions is a Google Ad on the Gui.</li>
<li><strong>It's light</strong>: built using Ajax, having MySQL and PHP on the server side, it's as light and fast as it gets...</li>
<li><strong>It's throughput friendly</strong>: in order to get the closest to real-time chatting possible without sending hundreds of requests per minute, it optimizes each call to the server by sleeping on the server side in case it doesn't find any new messages. The end result is less connection initiations, which means less throughput, which means that your hosting company won't get rich on your expense.</li>
<li><strong>It's safe</strong>: all my coding was done having safety in mind. If you find a bug, please do feel free to send me an email or add it to the Wish List page on the hot-site.</li>
<li><strong>It's cross-browser friendly</strong>: tested on Mozilla Firefox and MS IE. Seriously, why <strong>doesn't</strong> MS follow the standards?! Web developers should stop hacking their code to get it to work with IE's non-complience. But that's subject for another topic... this is not the place to rant.</li>
<li><strong>It's easy to install</strong>: follow the steps on the <a href="http://mywebchat.usestrict.net/install.php" target="_blank">Install</a> page to get your ChatMasterId and post the &lt;IFRAME&gt; code on the page you want it to show. That's it.</li>
<li><strong>It's multi-lingual</strong>: So far the site and the app come in 2 languages: English and Brazilian Portuguese. French is in the making and should be available in the next couple of weeks. If you'd like to see it in another language and would like to help out, <a href="http://mywebchat.usestrict.net/contact.php">get in touch</a>.</li>
</ul>
<h3>What it's NOT:</h3>
<ul>
<li><strong>It's NOT</strong> something that needs to be downloaded and installed in each client machine.</li>
<li><strong>It's NOT</strong> something that you as a webmaster will have to download into your site's filesystem. All it takes is a snippet of code that you get from our <a href="http://mywebchat.usestrict.net">hot-site</a>.</li>
<li><strong>It's NOT</strong> an application that talks to existing IM software such as MSN, Yahoo!, Skype... but who knows, given enough incentive, it might one day become it.</li>
</ul>
<h3><strong>Pre-requisites:</strong></h3>
<ul>
<li>A modern web browser;</li>
<li>Javascript enabled;</li>
<li>Cookies enabled;</li>
</ul>
<p>Please let me know what you think of this app either here or preferably at the <a href="http://mywebchat.usestrict.net/wish_list.php" target="_blank">Wish List</a> page, or send me a message through the <a href="http://mywebchat.usestrict.net/contact.php">contact form</a>. Your opinion is important!</p>
<p><em><strong>Note:</strong> I'm having some issues with emails on the server I hosted the app in, and will be changing hosts pretty soon. Please be patient if it takes me a while to reply to any emails sent from the contact form, and ping me here if I don't reply at all - since it probably means I didn't get your email.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://usestrict.net/2009/03/11/mywebchat-im-with-your-sites-visitors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
