<?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>TimeWaster's Place &#187; ajax</title>
	<atom:link href="http://www.timewaster.de/tag/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.timewaster.de</link>
	<description>Programming, Design, Tekkie Stuff and more</description>
	<lastBuildDate>Wed, 04 Aug 2010 14:02:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The smallest AJAX framework ever</title>
		<link>http://www.timewaster.de/the-smallest-ajax-framework-ever/</link>
		<comments>http://www.timewaster.de/the-smallest-ajax-framework-ever/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 22:41:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programmierung]]></category>

		<guid isPermaLink="false">http://www.timewaster.de/?p=172</guid>
		<description><![CDATA[The most AJAX frameworks are bloated with many functions you&#8217;ll never use or need. Who wants 60 KB of JavaScript if your only need is to send and load data? I Don&#8217;t.
I have found somewhere a short howto for AJAX, and derived (rewritten) the smallest AJAX framework ever out of it:
var ajax = false;
if(window.XMLHttpRequest) ajax [...]]]></description>
			<content:encoded><![CDATA[<p>The most AJAX frameworks are bloated with many functions you&#8217;ll never use or need. Who wants 60 KB of JavaScript if your only need is to send and load data? I Don&#8217;t.</p>
<p>I have found somewhere a short howto for AJAX, and derived (rewritten) the smallest AJAX framework ever out of it:</p>
<pre><code>var ajax = false;
if(window.XMLHttpRequest) ajax = new XMLHttpRequest();
else if(window.ActiveXObject) {
	try { ajax = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) {
		try { ajax = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (e) {}
	}
}

function ajaxGetContent(type, url, parameter, output_function) {
	if(!ajax) eval(output_function + '(false);');
	ajax.onreadystatechange = function() {
		if(output_function != 'void' &#038;&#038; ajax.readyState == 4) {
			if(ajax.status == 200) eval(output_function + '(ajax.responseText);');
			else eval(output_function + '(false);');
		}
	}
	if(type == "post") {
		ajax.open('POST', url, true);
		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		ajax.send(parameter);
	} else {
		ajax.open('GET', url + ((parameter.length > 0)?"?":"") + parameter, true);
		ajax.send(null);
	}
}</code></pre>
<p>That&#8217;s short, isn&#8217;t it?</p>
<p>To get the data you want you have to simply call the function and define a function which will be called after the data arrives:</p>
<pre><code>ajaxGetContent('post', '/myURL/index.php', 'a=b', 'myDataCallBack');

function myDataCallBack(myContent) {
	if(myContent == false) {
		// something went wrong
	} else {
		// have fun with your data
	}
}</code></pre>
<p>And if you want to send data only and don&#8217;t care of the answer, use this syntax:</p>
<pre><code>ajaxGetContent('post', '/myURL/index.php', 'a=b', 'void');</code></pre>
<p>Some explanation:<br />
- type = How to send the data (Parameters). &#8220;post&#8221; or &#8220;get&#8221;.<br />
- url = Where to send it to.<br />
- parameter = URL-style parameters. Never use a question mark!<br />
- output_function = The function which will be called after the data is received.</p>
<p>This Tool is tested in Opera 9+10, Firefox 2+3 and MSIE 7+8.</p>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.timewaster.de/the-smallest-ajax-framework-ever/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
