Archive for the ‘Ajax’ Category

Fire(bug)

Tuesday, October 23rd, 2007

Note : Before you read this blog post, if you are a web developer/designer and you have never tried firebug, then stop all your work and try that.

As you might already know, the best tool to debug a web frontend is firebug. It’s really easy and efficient. When you get used to it, you can’t actually live without it.

I was working on a web project for several months now, and there was a very strange behavior on that site. Everytime I go there, firebug stops working. That’s very annoying specially when that site is AJAX (and when there are lot of bugs there ;)).

Today, I found what makes firebug stop. I was using “parent” as a variable name. The site works perfectly with it but firebug didn’t manage to handle that.

P2P Minds

Monday, April 30th, 2007

We have just finished a small project - p2p mind.. We’ll probably release the code as GPL, even though it might not be useful for many of you ;-)

check this out : http://www.sandaru1.com/p2pmind/

IOI Site is back

Tuesday, March 13th, 2007

Today, after going through a lot, I managed to get the ioi site running. Just drop in there if you are interested in programming.

The grader is written in C++, and the interface is written in PHP using AJAX. This whole project is open source, you can download it from the sourceforge project page. Current release version is bit old, hopefully I’ll upload the current working version tonight.

IE String arrays

Monday, January 29th, 2007

I was doing a japanese shopping site and coded a small escape function in javascript which is also works for shift-jis encoding. The native function screws up the encoding. It worked prefectly, and I went on coding. I was doing all the development in firefox and suddendly the login function stopped working in IE(Actually not stopped working, It never worked in IE). The problem was that I used the javascript string as an array of char but in IE, it doesn’t support that. If I want to access a character I have to use the charAt function. When I searched in the Internet, I found that this is so common but just blogged it anyway.

Web 2.0 is not AJAX

Saturday, November 25th, 2006

AJAX was becoming popular for last few years. With the word ‘AJAX’ another simple word came into play ‘Web 2.0’. Some of us have been thinking that Web 2.0 is just using AJAX in a site which is not so true. AJAX may be a key element of web 2.0 but not the basic concept. The basic idea of web 2.0 is “the content of the site is decided by its users”. AJAX and CSS is used to create a simple interface. With the use of AJAX, a user can do many things without refreshing the same page like a desktop application.

As you all know quite good examples (best known as web 2.0 winners) for web 2.0 are digg, flickr, del.icio.us, youtube. These sites are really popular, have a great amount of users everyday, and new content arrives in each minute. Of course the secrete is web 2.0, the content is decided by the users.

An AJAX mistake

Sunday, October 22nd, 2006

Yesterday (Saturday) I was running the IOI grader on university of moratuwa for their ACM selection tests. As far as the grader functionality is concerned, it worked perfectly. But unfortunately the grader interface was damn slow. There were only 26 contestants and it was on a 100 Mbps LAN. So, I had to restart the server time by time. So, I just looked at the log files and found out there was a huge number of requests. But why is that? Because our grader is using AJAX to grab the latest status. The AJAX script was generating a request for each 2-3 seconds. To make the things worst, those were keep-alive requests. So, not only that the server was using the maximum number of threads, the script keeps sending the requests to the same connection so the connection doesn’t break until it meets the maximum number of keep alive requests. When several guys are sending requests others have to wait in the queue. I simply changed the refresh time of the AJAX script and the number of maximum threads on the apache server. After that restarting the apache server solved the problem, more or less.

Jigsaw

Monday, August 28th, 2006

Download jigsaw.js samples.zip
Jigsaw is a small javascript framework for AJAX.

First you need to download the prototype library from http://prototype.conio.net/. Then include the javascripts in your header like this :

<script src="prototype.js" type="text/javascript" language="javascript"></script>
<script src=”jigsaw.js” language=”javascript” type=”text/javascript”></script>

After that you just have to call the request function.

<script>
var request = new Ajax.Request(’test.xml’);
</script>

It can be either a static xml page or dynamically generated one, it doesn’t matter. The xml file describes what to do next.

Here is a sample xml.

<?xml version="1.0" encoding="iso-8859-1"?>
<response>
<element id=”header”>World!</element>
<element id=”header” attribute=”style”>font-size:16px</element>
<element id=”image1″ attribute=”src”>picture2.jpg</element>
<script>alert(’Text inside script tags are executed’)</script>
</response>

Your html page should have two elements like this :
<div id="header">Hello</div>
<img id=”image1″ src=”picture1.jpg” />

It’ll update the content of the header div to “World!”, make the font size larger and the change the picture to “picture2.jpg”.

You can also create javascript objects.

<?xml version="1.0" encoding="iso-8859-1"?>
<response>
<object>
<attribute name=”name”>Person1</attribute>
<attribute name=”age”>20</attribute>
</object>
<object age=”30″>
<attribute name=”name”>Person2</attribute>
</object>
<object name=”Person3″ age=”40″ />
</response>

Then you have to create a function to process the objects.

function process_objects(response) {
for (var i=0;i<response.objects.length;i++) {
alert(response.objects[i].name+” = “+response.objects[i].age);
}
}

The request should be like -

var request = new Ajax.Request("objects.php",{onFinish:process_objects});

You can also access the XMLHTTP Object from response.transport

This function is called after the pre-processing, if you want to process something before pre-processing use onComplete option.

AJAX, wow it’s getting really popular

Saturday, June 24th, 2006

Yesterday, I was browsing through digg.com programming channel. Mmm.. Impressive, more than half of the stories are related to ajax. So, I decided to write about bit of ajax today.

The main advantage of AJAX is that it works like a desktop application; instead of refreshing the page every time you change something, you can interact with the server then and there. When we talk about the disadvantages, there are a lot; bookmarks, back button, search engine incompatibility, etc (there are hundreds of articles in the internet regarding these.. so, I’m not going to repeat those ;-) ). But use of some hacks will help you to avoid those problems.

There are plenty of AJAX frameworks, both client side and the server side ones. I have gone through many of them and found out that one of the bests is rico. This simple javascript client side framework also contains some animation effects and drag and drop feature.

If you had a careful look at the popular javascript frameworks, you’ll see that most of them are based on prototype. Prototype is a really powerful javascript framework which allows you to create classes.

When we consider about the server side languages, using php is really easy. It’s a simple light weighted language and php applications can be executed in almost any web server (of course only if it supports php).

So, this great combination of tools will make you ajax life easier; prototype, rico and php.

P.S. : As I have mentioned in an earlier post, firebug will help you a lot on debugging.

Rico = Javascript + XML = AJAX

Saturday, June 10th, 2006

After successfully finished an AJAX project (a simple AJAX Content Management System), this time I’m going to create a complete AJAX site. The CMS was created without using any 3rd party frameworks, and had a great time debugging the javascript code. So, this time I decided to use a framework.My choice was Rico – A client side javascript framework. It also provides some javascript animations and drag n drop features – haven’t tried those yet. Actually, this made my work much easier. If I want to update the value of an element, then I just have to create a piece of xml code, the framework parses it and updates the element automatically. But it only supports updating an element value, if I’m doing something outside that, I have to parse the code manually and do it. So, I created my own mini framework using Rico:). Now, it’s really easy.

When I was creating the CMS, the alerts did a great job ;). It really helped me to debug the javascript code. But this time, Rico blog directed me to a nice extension for firefox – FireBug. It’s really cool. Actually, the main advantage is, it captures all AJAX events. Simple and Useful.