<?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>Bernd Artmüller &#187; Developing</title>
	<atom:link href="http://berndartmueller.at/category/developing/feed/" rel="self" type="application/rss+xml" />
	<link>http://berndartmueller.at</link>
	<description>Blog from Bernd Artmüller</description>
	<lastBuildDate>Fri, 06 Nov 2009 08:42:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Introduction to CSS Pseudo Selectors</title>
		<link>http://berndartmueller.at/2009/05/15/introduction-to-css-pseudo-selectors/</link>
		<comments>http://berndartmueller.at/2009/05/15/introduction-to-css-pseudo-selectors/#comments</comments>
		<pubDate>Fri, 15 May 2009 13:15:23 +0000</pubDate>
		<dc:creator>Bernd</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Developing]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[:hover]]></category>
		<category><![CDATA[first-child]]></category>
		<category><![CDATA[pseudo elements]]></category>
		<category><![CDATA[pseudo selector]]></category>
		<category><![CDATA[selectors]]></category>

		<guid isPermaLink="false">http://berndartmueller.at/?p=209</guid>
		<description><![CDATA[In this article I'm writing about CSS Pseudo Selectors, which are really useful and also easy to use.]]></description>
			<content:encoded><![CDATA[<h2>Syntax</h2>
<pre class="css">selector:pseudo-class { property:  value }</pre>
<p>CSS Pseudo Selectors can also be used with classes</p>
<pre class="css">Selector.class:pseudo-class { property: value }</pre>
<h2>Common Pseudo Selectors</h2>
<p>We often use pseudo selectors on our websites and they are really important. I am talking about the link states.</p>
<pre class="css">a:link {color:#FF0000} /* unvisited link */
a:visited {color:#00FF00} /* visited link */
a:hover {color:#FF00FF} /* mouse over link */
a:active {color:#0000FF} /* selected link */</pre>
<p>Take care of the right order, otherwise they will not work.<br />
You can also combine the Pseudo-Classes with CSS Classes</p>
<pre class="css">a.red:visited {color:#FF0000}</pre>
<h2>The :first-child Pseudo-Class</h2>
<p>A really useful but most people do not know that it exists, is the :first-child selector. It matches the first child of another element. To make sure, that it is also working in Internet Explorer, a doctype must be declared<br />
In the example below, the selector matches the first &#8220;p&#8221; element and changes the text color to blue.</p>
<pre class="html">

<!--
p:first-child
{
color:blue
}
-->

Blue colored paragraph

Normal styled paragraph</pre>
<p>Now we are going to select every &#8220;i&#8221; element in the first &#8220;p&#8221; element of the document. It is really easy, we only have to write p:first-child i { }</p>
<pre class="html">

<!--
p:first-child i
{
color:blue
}
-->

I am <em>italic</em>. I am <em>italic</em>

I am <em>italic</em>. I am <em>italic</em></pre>
<p>In this example, the selector mathes the first &#8220;i&#8221; element in every &#8220;p&#8221; element.</p>
<pre class="html">

<!--
p > i:first-child
{
font-weight:bold
}
-->

I am <em>bold</em>. I am <em>bold</em>

I am <em>bold</em>. I am <em>bold</em></pre>
<p>That&#8217;s it. In the next article I&#8217;ll write about Pseudo elements in CSS, like :first-letter.</p>
]]></content:encoded>
			<wfw:commentRss>http://berndartmueller.at/2009/05/15/introduction-to-css-pseudo-selectors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial: How to make your first ajax request</title>
		<link>http://berndartmueller.at/2009/04/18/tutorial-how-to-make-your-first-ajax-request/</link>
		<comments>http://berndartmueller.at/2009/04/18/tutorial-how-to-make-your-first-ajax-request/#comments</comments>
		<pubDate>Sat, 18 Apr 2009 15:31:55 +0000</pubDate>
		<dc:creator>Bernd</dc:creator>
				<category><![CDATA[Developing]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[request]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xmlhttpobject]]></category>

		<guid isPermaLink="false">http://berndartmueller.at/?p=99</guid>
		<description><![CDATA[Today I want to show you a little tutorial to make your first ajax request. In this tutorial I'll make a request to the server and try to get the ajax.txt file. This is the first step to start ajax developing to improve the usability and accessibility of your website...]]></description>
			<content:encoded><![CDATA[<p>Today I want to show you a little tutorial to make your first ajax request. In this tutorial I&#8217;ll make a request to the server and try to get the ajax.txt file. This is the first step to start ajax developing to improve the usability and accessibility of your website. At the end of the tutorial you can also download the files and experiment with them.</p>
<p>So, let&#8217;s start.</p>
<h2>Step 1</h2>
<p>First we create a html markup like this one.</p>
<pre class="xhtml" name="code">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;First Ajax Request&lt;/title&gt;

&lt;/head&gt;

&lt;body&gt;
&lt;a href="test.txt"&gt;Get File&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Later, when we click on the &#8220;Get File&#8221; link, the file should be loaded into the browser.</p>
<h2>Step 2</h2>
<p>Next we have to import our javascript file.</p>
<pre class="xhtml" name="code">&lt;script type="text/javascript" src="ajax.js"&gt;&lt;/script&gt;</pre>
<p>Then we also add a click event handler on the link.</p>
<pre class="xhtml" name="code">&lt;a href="test.txt" onclick="getFile(this.href); return false;"&gt;Get File&lt;/a&gt;</pre>
<p>Whenever the user clicks on that link, the method &#8220;getFile&#8221; get called with a parameter, which represents the path to the file we want to load. The &#8220;return false&#8221; is required, if the browser successfully loaded the file, to deactivate the link and the browser doesn&#8217;t redirect us.</p>
<h2>Step 3</h2>
<p>Now create the file which you want to load in the browser, eg. text.txt and write something in it like &#8220;Hello World!&#8221;</p>
<h2>Step 4</h2>
<p>Create a new file and call it &#8220;ajax.js&#8221;. This will contain our functios for the request. First we&#8217;ll write a function to get the XMLHttp object. Start with creating a new instance of an XMLHttpRequest object</p>
<pre class="js" name="code">var xhr = new XMLHttpRequest();</pre>
<p>But it isn&#8217;t that simple in Internet Explorer. There you need to create a new instance of an ActiveX object.</p>
<pre class="js" name="code">var xhr = new ActiveXObject("Microsoft.XMLHTTP");</pre>
<p>Before creating the new instance, we have to test for the exisctence of the object.</p>
<pre class="js" name="code">if (window.XMLHttpRequest){
  xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
  try {
    xhr = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch(e) {
    try {
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
      xhr = false;
    }
  }
}</pre>
<p>Last we return the xhr object. Then the final function should look like this.</p>
<pre class="js" name="code">function getHTTPObject(){
  var xhr = false;

  if (window.XMLHttpRequest){
    xhr = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) {
    try {
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e) {
      try {
         xhr = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        xhr = false;
      }
    }
  }
  return xhr;
}</pre>
<h2>Step 5</h2>
<p>The next step is to send the request and receive the file. So we write a function &#8220;getFile&#8221; with one parameter, which expects the path of the file we want to load in the browser. Then we create the first time a instance of the XMLHttpObject.</p>
<pre class="js" name="code">function getFile(file){
  var request = getHTTPObject();
}</pre>
<p>The getHTTPObject function could has returned a value of false, which means that the browser does not have Ajax capabilities. So we have to check this with an easy if condition.</p>
<pre class="js" name="code">if (request){
  //Do some Ajax
}</pre>
<p>Now we have created an instance of XMLHttpRequest and we are ready to send a request to the server.</p>
<h2>Step 6</h2>
<p>To do this, there are three components.</p>
<p>1. The onreadystatechange event handler<br />
2. The open method<br />
3. The send method</p>
<p><strong>ONREADYSTATECHANGE</strong></p>
<p>This is an event that is triggered by the server, not by the user. During an Ajax operation, the server sends updates to the client about the current status of the communication. This is done by updating a property of the XMLHttpRequest object. It&#8217;s called readyState. Every time the readyState property is changed, the readystatechange event is triggered. If you register a function to this event handler, the function will be executed every time the server pings the client with an update.</p>
<pre class="js" name="code">if (request){
  request.onreadystatechange = DoSomething;
}</pre>
<p>In the next step, we have to specify the details of the Ajax request.</p>
<h2>Step 7</h2>
<p>To specify the details of the Ajax request, such as the url of the file you want to request, &#8220;GET&#8221; or &#8220;POST&#8221; and a boolean which indicated whether the request should occour asynchronously or not. For our example we use &#8220;GET&#8221; and true, because we want an asynchronous request.</p>
<pre class="js" name="code">function getFile(file){
  var request = getHTTPObject();

  if (request){
    request.onreadystatechange = DoSomething;
    request.open("GET", file, true);
    request.send(null);
  }
}</pre>
<h2>Step 8</h2>
<p>Now we have a succesfull request, the only thing we have to do now, is to receive the response and display it. We can do this, with checking two propertys.</p>
<p><strong>READYSTATE</strong></p>
<p>It indicates the current state of an Ajax request.</p>
<p>0 Uninitialized. The open methond hasn&#8217;t been called yet.<br />
1 Loading. The open method has been called, but the send method hasn&#8217;t.<br />
2 Loaded. The send method has been called. The request has started.<br />
3 Interactive. The server is in the process of sending a response.<br />
4 Complete. The server has finished sending a response.</p>
<p>So we have to check the status of this object and wait until it&#8217;s value reached 4.</p>
<pre class="js" name="code">function displayResponse(request){
  if (request.readyState == 4){
    //Do something with the response
  }
}</pre>
<p>The other property we have to check now it the status property. It&#8217;s a three-digit numerical value. The most common status code is 200, which means &#8220;OK&#8221;. Other codes are 403 for &#8220;forbidden&#8221;, 404 for &#8220;Not Found&#8221; and 500 for &#8220;Internal Server Error&#8221;. By comparing this property to a value of 200, you can be sure that the server has sent a successful response.</p>
<pre class="js" name="code">if (request.readyState == 4){
  if (request.status == 200 || request.status == 304){
    //Display the response
  }
}</pre>
<p>The last thing is to display the received response in the browser and register this function to the onreadystatechange property.</p>
<pre class="js" name="code">var node = document.createElement("p");
var text = document.createTextNode(request.responseText);
node.appendChild(text);
document.getElementsByTagName("a")[0].parentNode.insertBefore(node, document.getElementsByTagName("a")[0]);</pre>
<p>The request.responseText property contains the data sent from the server. Depending on what the server is  sending, this might be a string of HTML, XML or just a string of text.</p>
<p>And now register this function to the onreadystatechange property.</p>
<pre class="js" name="code">request.onreadystatechange = function(){ displayResponse(request) };</pre>
<p>That&#8217;s it. It&#8217;s the basic of Ajax and now you are able to learn more details of Ajax and how to improve Usability with Ajax.</p>
<h2><a href="http://berndartmueller.at/wp-content/uploads/2009/04/first_ajax_request.rar">Download source files</a></h2>
]]></content:encoded>
			<wfw:commentRss>http://berndartmueller.at/2009/04/18/tutorial-how-to-make-your-first-ajax-request/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
