<?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>dotvoid.com &#187; remote scripting</title>
	<atom:link href="http://www.dotvoid.com/tag/remote-scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotvoid.com</link>
	<description>Experiments and thoughts in PHP and javascript</description>
	<lastBuildDate>Tue, 11 Oct 2011 12:49:15 +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>Remote Scripting (AJAX) framework</title>
		<link>http://www.dotvoid.com/2005/03/remote-scripting-ajax-framework/</link>
		<comments>http://www.dotvoid.com/2005/03/remote-scripting-ajax-framework/#comments</comments>
		<pubDate>Wed, 30 Mar 2005 15:15:28 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[remote scripting]]></category>

		<guid isPermaLink="false">http://www.commodi.com/?p=45</guid>
		<description><![CDATA[
Spare time to spend on interesting projects is not plentiful nowadays. Even so I have managed to put quite a few hours into a small web application framework. My goal is to make it easier to develop web applications that heavily depend on client server communication. I really want to get rid of the painfully [...]]]></description>
			<content:encoded><![CDATA[<div class="preamble">
<p>Spare time to spend on interesting projects is not plentiful nowadays. Even so I have managed to put quite a few hours into a small web application framework. My goal is to make it easier to develop web applications that heavily depend on client server communication. I really want to get rid of the painfully boring and repetetive task of validating form data and sending it to a backend in PHP where the data has to be validated again. The framework is based on XMLHttpRequest for the communication between the client and the server. This kind of communication is commonly known as Remote Scripting. Some people (not me) likes to use the new, more catchy, acronym AJAX. Anyway, this is a sneak peak on how the framework will be used.</p></div>
<h3>Introduction</h3>
<p>First I had a look at JPSpan and other similar implementations. Impressive as JPSpan is, I thought it a bit too much for me. I don&#8217;t need, or want, transparancy between javascript and PHP classes. To be honest, I really don&#8217;t like hiding the communication between client and server as it mostly creates problems. Pretending that the network isn&#8217;t there usually gives birth to architectures with a huge amount of method calls over the network. It is better to work with data on the client side, validate it and then send it to the server for the real work. However I did like the serialization into a streamlined XML format and thus I have adapted that in my solution.</p>
<p>The framework which has the wonderfully dry working name of SSRS is getting more and more complicated. I started working on a simple synchronous http communication between javascript and PHP. Now I am ending up with a framework for binding form fields to method calls with automatic validation of data. Still I think it is going to be really useful when production ready.</p>
<h3>The HTML form</h3>
<p>What is it then and what you do you do with it you ask? To show it off a bit I&#8217;ll give you a simple example. The below form is an extremely simple user form. It features a readonly field for the unique user id which of course will be empty when we create new users. When I use this form to create a new user I don&#8217;t want the page to reload. It is unecessary slow. But I still want the User_id field populated when the user has been saved.</p>
<pre>&lt;form id="User" onsubmit="return saveUser();"&gt;
&lt;fieldset&gt;
    &lt;legend&gt;User details&lt;/legend&gt;

    &lt;label id="lbl_User_id"&gt;Userid&lt;/label&gt;
    &lt;input type="text" readonly="1" id="User_id" /&gt;

    &lt;label id="lbl_User_login"&gt;User login&lt;/label&gt;
    &lt;input type="text" id="User_login" /&gt;

    &lt;label id="lbl_User_email"&gt;Email&lt;/label&gt;
    &lt;input type="text" id="User_email" /&gt;
    &lt;a href="#" onclick="return saveUser();"&gt;Save&lt;/a&gt;
&lt;/fieldset&gt;
&lt;/form&gt;</pre>
<p>I have added an onsubmit handler and a link that both call the javascript function saveUser(). I could just as well have used a normal submit button.</p>
<h3>The PHP class</h3>
<p>To handle users I have created a User class implemented in PHP. The class have a save() method that takes id, login and email as parameters. The id is not mandatory. To be able to return more data than just a value, result data is always returned as key value pairs in an array. When errors or problems are encountered exceptions are thrown which automatically will be passed to the client as javascript exceptions.</p>
<pre>class User
{
  public function save($id, $login, $email)
  {
    if ($id == null || $id == 0)
      {
        error_log("Creating new user");
        // Validate data
        // Save user
        // Retrieve the new numerical user id in $id
        $id = 1; // For the example
        return Array('id' =&gt; $id);
      }
    throw new Exception("Updating a user is not implemented");
  }
}</pre>
<h3>Tying them together</h3>
<p>So what do I as a developer need to do to connect these two loose ends? Before we create the saveUser() function mentioned above we need to setup the form against SSRS. A few lines of javascript in an onload handler or an explicitly called init function is needed.</p>
<pre>var g_user = null;
var frm = null;

frm = new Array(
	new Array('User_id', 'number', '', '', false, '', ''),
	new Array('User_login', 'string', 'A unique login',
		'Login not valid or not unique', true, 4, 8, ''),
	new Array('User_email', 'email', 'Email address is required',
		'Email is not valid', true));

g_user = new RemoteObject('postHandler.php', 'User');
g_user.bindFields(frm);
g_user.bindParams('save', 'User_id', 'User_login', 'User_email');</pre>
<p>What the above essentially does is:</p>
<ol>
<li>Create the client object and tell it what server class to use and which URI to communicate with. The postHandler.php is the backend implementation.</li>
<li>Create a structure that describes field data types, help and error messages, max/min length, etc.</li>
<li>Bind the form to the client object and bind form fields as parameters to method calls.</li>
</ol>
<p>The framework can handle strings, numbers, decimals, emails, string lists and more. For each datatype it is possible to set various constraints. For some datatypes it is also possible to specify your own regular expression to use as validation.</p>
<p>When this is done we can create the actual saveUser() function.</p>
<pre>function saveUser()
{
  var result;
  try
    {
      result = g_user.execute('save');
      document.getElementById('User_id').value = result.item(0);
    }
  catch(ex)
    {
      alert(ex.message);
    }
  return false;
}</pre>
<p>That is all. As we have bound the form to the g_user object all the fields are validated prior to being sent to the server. The error messages specified for the fields above will be displayed if needed. Any exception on the server side will also be displayed in the same way. As the fields User_id, User_login and User_email are bound to the save method they will automatically be handed over the PHP method save() in the User class.</p>
<h3>Conclusion</h3>
<p>The data being sent between client and server is encoded in a simple streamlined XML format and is always validated against a DTD to ensure the data is encoded correctly. This does not mean that you don&#8217;t need to check the data on the server side but it does add an extra layer of data security. It is also a lot simpler to validate the parameters in a method, where it should be done, than filtering $_GET or $_POST arrays before calling PHP functions or methods.</p>
<p>The benefits of using a framework like this is that it lets the developer concentrate on the functionality. Another benefit is that it does not interfere with your choice of template engine. I have a few things left to iron out before I release the code.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://www.dotvoid.com/2005/03/remote-scripting-ajax-framework/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.dotvoid.com/2005/03/remote-scripting-ajax-framework/&amp;title=Remote+Scripting+%28AJAX%29+framework" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.dotvoid.com/2005/03/remote-scripting-ajax-framework/&amp;t=Remote+Scripting+%28AJAX%29+framework" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.dotvoid.com/2005/03/remote-scripting-ajax-framework/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.dotvoid.com/2005/03/remote-scripting-ajax-framework/&amp;title=Remote+Scripting+%28AJAX%29+framework&amp;summary=%0D%0A%0D%0ASpare%20time%20to%20spend%20on%20interesting%20projects%20is%20not%20plentiful%20nowadays.%20Even%20so%20I%20have%20managed%20to%20put%20quite%20a%20few%20hours%20into%20a%20small%20web%20application%20framework.%20My%20goal%20is%20to%20make%20it%20easier%20to%20develop%20web%20applications%20that%20heavily%20depend%20on%20client%20server%20communication.%20I%20really%20want%20to%20get%20rid%20of%20&amp;source=dotvoid.com" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-plaxo">
			<a href="http://www.plaxo.com/?share_link=http://www.dotvoid.com/2005/03/remote-scripting-ajax-framework/" rel="nofollow" class="external" title="Share this on Plaxo">Share this on Plaxo</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.dotvoid.com/2005/03/remote-scripting-ajax-framework/&amp;title=Remote+Scripting+%28AJAX%29+framework" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Remote+Scripting+%28AJAX%29+framework+-+http://b2l.me/wy3cx&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotvoid.com/2005/03/remote-scripting-ajax-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remote scripting with SRSS</title>
		<link>http://www.dotvoid.com/2004/12/remote-scripting-with-srss/</link>
		<comments>http://www.dotvoid.com/2004/12/remote-scripting-with-srss/#comments</comments>
		<pubDate>Wed, 29 Dec 2004 16:21:16 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[remote scripting]]></category>

		<guid isPermaLink="false">http://www.commodi.com/?p=38</guid>
		<description><![CDATA[
I have ever since I wrote my old article on remote scripting using the script tag been intrigued by the possibilities of &#8220;behind the scenes&#8221; communication. Then Harry Fuecks started writing about XMLHttpRequest and how to connect it with PHP in a seamless manner resulting in JPSpan. The result works much like CORBA (or like CORBA was [...]]]></description>
			<content:encoded><![CDATA[<div class="preamble">
<p>I have ever since I wrote my old <a href="http://www.dotvoid.com/view.php?id=13">article on remote scripting</a> using the script tag been intrigued by the possibilities of &#8220;behind the scenes&#8221; communication. Then Harry Fuecks started writing about XMLHttpRequest and how to connect it with PHP in a seamless manner resulting in <a href="http://jpspan.sourceforge.net/">JPSpan</a>. The result works much like CORBA (or like CORBA was supposed to work).</p>
<p>You as application developer shouldn&#8217;t be bothered about whether the object you work on is sitting on the client or the server. However good I found JPSpan a bit much for me as I normally just send pieces of data back and forth. Whence my own SSRS&#8230;</p></div>
<div class="itemview">
<h3>SSRS</h3>
<p>I decided JPSpan was a bit much and started to hack up my own solution; SRRS <em>(Project now dead and gone)</em>. Not a good name I know.</p>
<p>One thing I did like about JPSpan was the XML serialization that took place automatically. It makes it fairly easy to write a backend in most modern languages. As for me I mostly use PHP as the backend. Beginning with PHP5 there is finally good support for all the different XML technologies.</p>
<p>SSRS does not hide the remote classes. There are two different ways of calling remote scripts; post() and execute(). Both are synchronous and both are very similar. The latter, execute(), could be wrapped to handle execution of methods on remote classes whereas post() only send data back and forth. My main goal was that it should be simple to send and retrieve named variables from a backend so I&#8217;ll concentrate on the post() method here.</p>
<h3>The client side</h3>
<p>In javascript you would write for example</p>
<pre>var result;
var props = new Array();
var obj;</pre>
<pre>props["login"] = "dotvoid";
props["fullname"] = "Danne Lundqvist";
props["age"] = 29;</pre>
<pre>try {
  obj = new RemoteObject('postHandler.php', 'User');
  result = obj.post(props);
  len = result.length();
  for (n = 0; n &lt; len; n++) {
    alert(result.id(n) + " is " + result.item(n));
  }
}
catch(ex) {
  alert('Err: ' + ex.code);
}</pre>
<h3>Behind the scenes</h3>
<p>This automatically would get serialized to the XML below and sent via a synchronous http POST call to postHandler.php. I&#8217;m not sure if it is a good idea to always encode strings in CDATA but it sure makes life simpler.</p>
<pre>&lt;class name="User"&gt;
&lt;s id="login"&gt;&lt;![CDATA[dotvoid]]&gt;&lt;/s&gt;
&lt;s id="fullname"&gt;&lt;![CDATA[Danne Lundqvist]]&gt;&lt;/s&gt;
&lt;i id="age" v="29"/&gt;
&lt;/class&gt;</pre>
<h3>The backend</h3>
<p>I haven&#8217;t created a nice backend just yet but reading this in PHP is very simple using, for example, DOM. The only thing I do before reading it is adding a DOCTYPE with the DTD. The DTD defines the id attributes to be of the type ID so that I can use getElementById() to retrieve elements from the XML. Btw, this does not seem to work in javascript for some reason. Very annoying!</p>
<pre>$dtd = "&lt;!DOCTYPE class SYSTEM \"postHandler.dtd\"&gt;";</pre>
<pre>$doc = new DOMDocument("1.0");
$doc-&gt;loadXML("$dtd\n$HTTP_RAW_POST_DATA");
$doc-&gt;validate();</pre>
<pre>$fullname = $doc-&gt;getElementById('fullname')-&gt;nodeValue;
$login = $doc-&gt;getElementById('login')-&gt;nodeValue;
$age = $doc-&gt;getElementById('age')-&gt;getAttribute('v');</pre>
<p>Sending data back to the client should be done via a automatic serialization of data as well. But till that is in place it is very simple to send data back to the client. Below is a quite stupid &#8211; but simple &#8211; example.</p>
<pre>header('Content-Type: text/xml; charset=UTF-8');
echo '&lt;class name="User"&gt;&lt;i id="result" v="0"/&gt;&lt;/class&gt;';</pre>
<h3>Conclusion</h3>
<p>It works and the codebase is very small. It suit my needs a lot better than hiding class method invocations which JPSpan does. Right now it is only synchronous and does not handle timeouts or errors grazefully. In addition there are a few things left before it fiels production worthy. So it will grow some more.</p>
<p>I have also started</p>
<p>Try it if you are so inclined and <a href="http://www.dotvoid.com/about.php">tell me</a> if you think it could be useful or just a duplication of effort and as such a waste of time.</div>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://www.dotvoid.com/2004/12/remote-scripting-with-srss/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.dotvoid.com/2004/12/remote-scripting-with-srss/&amp;title=Remote+scripting+with+SRSS" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.dotvoid.com/2004/12/remote-scripting-with-srss/&amp;t=Remote+scripting+with+SRSS" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.dotvoid.com/2004/12/remote-scripting-with-srss/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.dotvoid.com/2004/12/remote-scripting-with-srss/&amp;title=Remote+scripting+with+SRSS&amp;summary=%0D%0A%0D%0AI%20have%20ever%20since%20I%20wrote%20my%20old%20article%20on%20remote%20scripting%20using%20the%20script%20tag%20been%20intrigued%20by%20the%20possibilities%C2%A0of%20%22behind%20the%20scenes%22%20communication.%20Then%20Harry%20Fuecks%20started%20writing%20about%20XMLHttpRequest%20and%20how%20to%20connect%20it%20with%20PHP%20in%20a%20seamless%20manner%20resulting%20in%20JPSpan.%C2%A0The%20result&amp;source=dotvoid.com" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-plaxo">
			<a href="http://www.plaxo.com/?share_link=http://www.dotvoid.com/2004/12/remote-scripting-with-srss/" rel="nofollow" class="external" title="Share this on Plaxo">Share this on Plaxo</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.dotvoid.com/2004/12/remote-scripting-with-srss/&amp;title=Remote+scripting+with+SRSS" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Remote+scripting+with+SRSS+-+http://b2l.me/wtzpk&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotvoid.com/2004/12/remote-scripting-with-srss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remote scripting with javascript</title>
		<link>http://www.dotvoid.com/2002/08/remote-scripting-with-javascript/</link>
		<comments>http://www.dotvoid.com/2002/08/remote-scripting-with-javascript/#comments</comments>
		<pubDate>Tue, 13 Aug 2002 08:15:07 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[remote scripting]]></category>

		<guid isPermaLink="false">http://www.commodi.com/?p=21</guid>
		<description><![CDATA[
I am currently working on a web based instant messenger client. In creating this I faced the problem of how to manipulate the web client from the server side. I didn&#8217;t want the client to reload every time it needed to check for status changes of contacts, new messages, send messages and what not. When [...]]]></description>
			<content:encoded><![CDATA[<div class="preamble">
<p>I am currently working on a web based instant messenger client. In creating this I faced the problem of how to manipulate the web client from the server side. I didn&#8217;t want the client to reload every time it needed to check for status changes of contacts, new messages, send messages and what not. When supporting thousands of users this generates a lot of traffic. So for this I needed a way for the server to send commands to the client. A stable lightweight remote scripting solution.</p></div>
<h3>Introduction</h3>
<p>An article on <a href="http://developer.apple.com/internet/javascript/iframe.html">remote scripting using iframes</a> inspired me to write about how I solved the problem. I think that my solution is cleaner although not as backwards compatible. Early on in my IM project I decided to create a web client completely based on HTML dom manipulation through the use of javascript. This does not work in the old generation browsers ofcourse. However, I think the benefits definitely outweigh the drawbacks. And since this works nicely in both IE and Netscape I think it is very appealing. It should also work with newer versions of Opera but I haven&#8217;t tested it.</p>
<p>The client is nothing more than a small web page. This web page need to send commands to the server and as a result receive javascript function calls. I also wanted the client to automatically do this so the user didn&#8217;t have to click a refresh button every time.</p>
<h3>The server</h3>
<p>For this example I&#8217;ll use a simple &#8220;server script&#8221; that is nothing more than a finished javascript file. It only contains one command that displays a dialog box to let you know it&#8217;s loaded. Let&#8217;s name this file &#8220;server.js&#8221;.</p>
<pre><code>alert('Hello client, I am the server!');</code></pre>
<p>In a real solution the server script might probably be php, asp, jsp or any choice of server solution that generates javascript. This, server.js however, is enough for this example.</p>
<h3>The client</h3>
<p>The client web page is a bit more complex but not much. I want the client to poll the server for new commands with an interval of, for example, thirty seconds. This is done easily with javascript using the statement setInterval. Below, the jsFunction will be called every 30th second.</p>
<pre><code>function jsFunction() {
	...
}
id = setInterval(jsFunction, 30000);</code></pre>
<p>To stop the interval you use the id you get as a return value from setInterval, using the statement clearInterval.</p>
<pre><code>clearInterval(id);</code></pre>
<p>This is simple enough. However, now we want the function to actually do something useful. We want it to actually poll the server. I have solved this by dynamically inserting a new script element in the page header. This script element is supplied with the url to our server file. This is how you create the script element and set it&#8217;s attributes.</p>
<pre><code>var script = document.createElement('script');
script.src = 'server.js';
script.type = 'text/javascript';
script.defer = true;</code></pre>
<p>Now we have a script tag created dynamically. This is not all though. For this script, server.js, to be loaded we need to obtain a reference to the html head element and insert the script element there.</p>
<pre><code>var head = document.getElementsByTagName('head').item(0);
head.appendChild(script);</code></pre>
<p>What I have described now is actually all code you need to start playing with remote scripting. However, every time you load new commands from the server.js you add a new element to the web page. It might be nice to remove old commands before loading new ones. So each time we create the script element we name it with an id so that we can easily find it. Before we load the new script commands we try to find the old script element. If we find it we remove it.</p>
<pre><code>var head = document.getElementsByTagName('head').item(0);
script.id = 'lastLoadedCommands';
var old = document.getElementById('lastLoadedCommands');
if (old) head.removeChild(script');</code></pre>
<h3>Conclusion</h3>
<p>Well that&#8217;s it. Below you can see the finished client. It is, as you can see, quite simple and there are very few lines of code. The simpler it is, the easier it is to extend. The best part is that it follows the standards as set by the W3C. This should as a result be supported by every standard compliant browser. This particular example is tested with a two weeks old Mozilla (Netscape 6.x) and Internet Explorer 5.0. I suspect though that it will work with Opera as well. If you have questions, comments or critisism &#8211; please feel free to use the forums.</p>
<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My client&lt;/title&gt;

&lt;script type="text/javascript"&gt;
var g_remoteServer = 'server.js';
var g_intervalID;

function callServer() {
	var head = document.getElementsByTagName('head').item(0);
	var old  = document.getElementById('lastLoadedCmds');
	if (old) head.removeChild(old);

	script = document.createElement('script');
	script.src = g_remoteServer;
	script.type = 'text/javascript';
	script.defer = true;
	script.id = 'lastLoadedCmds';
	void(head.appendChild(script));
}

g_intervalID = setInterval(callServer, 30000);
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
This is the simple client.

&lt; a href="javascript:callServer();"&gt;Call server now!&lt; /a&gt;;

&lt; a href="javascript:clearInterval(g_intervalID);"&gt;Stop polling&lt; /a&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://www.dotvoid.com/2002/08/remote-scripting-with-javascript/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.dotvoid.com/2002/08/remote-scripting-with-javascript/&amp;title=Remote+scripting+with+javascript" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.dotvoid.com/2002/08/remote-scripting-with-javascript/&amp;t=Remote+scripting+with+javascript" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.dotvoid.com/2002/08/remote-scripting-with-javascript/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.dotvoid.com/2002/08/remote-scripting-with-javascript/&amp;title=Remote+scripting+with+javascript&amp;summary=%0D%0A%0D%0AI%20am%20currently%20working%20on%20a%20web%20based%20instant%20messenger%20client.%20In%20creating%20this%20I%20faced%20the%20problem%20of%20how%20to%20manipulate%20the%20web%20client%20from%20the%20server%20side.%20I%20didn%27t%20want%20the%20client%20to%20reload%20every%20time%20it%20needed%20to%20check%20for%20status%20changes%20of%20contacts%2C%20new%20messages%2C%20send%20messages%20and%20what%20not&amp;source=dotvoid.com" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-plaxo">
			<a href="http://www.plaxo.com/?share_link=http://www.dotvoid.com/2002/08/remote-scripting-with-javascript/" rel="nofollow" class="external" title="Share this on Plaxo">Share this on Plaxo</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.dotvoid.com/2002/08/remote-scripting-with-javascript/&amp;title=Remote+scripting+with+javascript" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Remote+scripting+with+javascript+-+http://b2l.me/wv3ag&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotvoid.com/2002/08/remote-scripting-with-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

