Posts Tagged Ajax

Fire(bug)

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.

Tags: , , ,

Web 2.0 is not AJAX

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.

Tags: ,

An AJAX mistake

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.

Tags: ,

Jigsaw

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.

Tags: ,

AJAX, wow it’s getting really popular

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.

Tags: ,

Get Adobe Flash playerPlugin by wpburn.com wordpress themes