How to get updated data using AJAX

A common use of AJAX is to get some data from a database and then display it on a web-page.

Also a common issue with AJAX calls is that it intercepts the request for data and tries to handle it locally. If it can’t only then is the request forwarded to the server. This is done to improve the performance of the web-page.

But this can have a serious side effect where after the first call to the server for data, subsequent requests are handled locally even though the data on the server side may have changed.

This is, most often, caused by a standard request string being used again and again.

For example if you want to fetch data from table ‘employee’ to display a list of employees then your request string (for HTTP GET) might look something like:

awebpage.jsp?table=employee&action=list

After getting the initial list of employees if any changes are made in the database they will not be reflected on the webpage even if you click the refresh button on the browser. The only way you will be able to see the ‘fresh’ data is if you reopen the page in a new browser window.

This is because every time the data listing request is sent using AJAX the XMLHttpRequest is intercepted by the browser, the request string checked and if found the same the request is responded to at the client side itself using cached data. Thus the ‘fresh’ data is never obtained from the server because it never gets the request for ‘data’.

How to solve this?

It is very simple to solve this problem. Just add a parameter with changing values to the string. For example:

awebpage.jsp?table=employee&action=list&rndparameter=10

Here the ‘rndmparameter’ parameter will have a random number assigned to it every time the request is made. This will make the request string different every time. Thus the request will be forwarded to the server and not be handled locally.

The  parameter can have any name and any changing value. It need not even be random value. You could toggle a boolean variable ‘true’ and ‘false’ between subsequent requests.

Work, Love, Skills and Earth

Sigmund Freud, the famous psycho-analyst, proposed that work and love give stability and meaning to our minds. I read an interesting extension to this in Parallel Worlds by Michio Kaku.

Work because it helps give us a ‘sense of responsibility and purpose, a concrete focus on our labours and dreams’ (from Parallel Worlds by Michio Kaku).

Love because it puts us within ‘the fabric of society’ and ‘gives us roots’. Without it we become ‘drifters in our own land, unattached to the concerns of others’ (from Parallel Worlds by Michio Kaku).

Michio Kaku proposes two other things that can give ‘stability and meaning’ to our minds.

Developing our skills for the benefit of society in general. To achieve our maximum potential. Everyone has problems but we all have certain skills which can be developed to overcome those problems.

Improve the world around us, do something for the benefit of mankind in general. Clean up our neighbourhood, help someone in need or just be kind to someone.

The Hands of Man

Today someone shared quite a remarkable thought with me so I thought I would share it with the world!

A new born baby has a clenched fist. The tightly closed fist represents the hunger for life. It represents the desire to grab the most out of this chance to be alive.

But when a person dies their hands always end up in an open and relaxed position. This highlights the fact that we cannot take ANYTHING with us. There comes a time to let go of all the things material.

A Day at the Registrar’s Office

One would think a Registrar’s Office where probably crores worth of property changes hands every day life is pretty dull and weighed down under thick dusty files. But no! Any place where big things happen (like people buying their first house or probably registering their last will) can be anything but dull. In fact it is full of stories!

One would wonder why is the place not clean and how come people who can spend lakhs to buy a property do not have civic sense to use a dustbin. Why don’t the civic authorities have common sense to put dustbins in a place visited by hundred of people a day!

There was a large group of young Army jawans there to register their wills. People who don’t have control over their destiny. I wonder how it must feel to write out your will knowing that it might be used soon.

There were photographs I took, some sad, some funny and some fascinating.  There was life in all its glory. Intersection of different life-flows. All in all it was a very interesting day out at the crossroads of life.

Stone slab announcing the installation of computers at the govt. office!
Stone slab announcing the installation of computers at the govt. office!

Heaps of Garbage..
Heaps of Garbage..

 

Patterns on water..
Patterns on water..

🙂

Man is not God… God is not man…

‘Man is not God’ is a phrase that is often used when ‘science’ tries to encroach upon what is believed to be the realm of ‘God’ (e.g. cloning and stem cell research).

Obviously the term ‘man’ is loosely used and I use it here in the wider context to represent both men and women.

I also heard this phrase in a movie the other day. But all of a sudden my brain turned this line around and presented it to me. It gave me quite a lot to think about. Here is the phrase turned around:

‘God is not man’

Man needs science because man is not God. God is not man therefore God has no need for science. God does not die (we assume?), does not need food (again assume?) so why would God DO science? God is all knowing and all seeing. This surely makes ‘science’ a useless tool for God.

When people say that Man should not try and play God (for example when we fiddle around with DNA to create new life forms such as GM crops) my question is since God is not man how does he (or she) know about the problems of being a human?

Man needs science to improve his life. God has no need for science. So why stop the spread of science? Why ban stem-cell research which has the potential of helping millions of people suffering from problems like diabetes?

That is because man does not know how to use science for benefit of mankind in general. Science becomes either a gun to hold against someone or a pile of money.

This is a debate which has no end. God can aspire man to achieve great things. At the same time if we realise God is not man then our perception of ‘what is God’ will change and this debate will end. That is when we will realise ‘God’ is not a destination, it is a journey.

Indian Foreign Policy – Himesh Reshammiya Style

‘Jhalak dikhla jaa’ (show me a glimpse) is one of the most popular songs sung by Himesh Reshammiya.

These days India seems to be taking their foreign policy decisions based on the above song. Few days ago I saw a news item on NDTV which talked about how India was concerned that US was getting closer to Pakistan. The major reason for this was that over the last month or so the Indian Government had been busy with the General Elections. During that time Pakistan had been busy warming up to the new US administration.

When the Indian politicians suddenly woke up to this fact towards the end of the election process they appeared desperate to see a glimpse of US engagement and interest in India.

As one big drama ends the next one is about to begin, the Indian politicians are  singing ‘jhalak dikhlaa jaa’ for the new US President.

Thumbs-UP!

How important is the thumb to the ‘Thumb Generation’?

If you are wondering what the ‘Thumb Generation’ is – the answer is simple. We are the ‘Thumb Generation’! This term refers to the popularity of various electronic devices (like cellphones) which we operate using our thumbs. These devices have become an important part of our lives. Thus we are the ‘Thumb Generation’.

Obviously the thumb is VERY important (if not critical) to the ‘Thumb Generation’. How important it really is I discovered only recently.

Some time ago I managed to cut my thumb. The cut required a band-aid. This meant that the top half of my thumb was covered in a plastic band-aid for two-three days.

Now this is a fairly common thing to happen to anyone. But being a part of the ‘Thumb Generation’ it made things bit weird for me. Here is how:

 – Tried to use my touchscreen phone… the screen wouldn’t work because my thumb was covered by the band-aid!

– Tried to use the keypad on the mobile… thumb kept slipping because of the band-aid.

– Tried to play a video game but my thumb started hurting.

– I couldn’t even scratch my head!

The Fact of Indian Elections

Every conflict has three sides. The side which won, the side which lost and the side which sits on the side to watch the conflict to take all possible advantage.

During the current election period we find parties in power taking fire from parties which lost the last election. The loosers blaming the winners for the almost continuous sorry state of affairs in India. The winners in turn blaming the losers who were in power previously. This blame game has no end unfortunately.

In all this one critical fact never gets highlighted: the amount of time a government gets to plan and implement development work.

Is it right for Congress to blame BJP which was previously in power? Is it right for the BJP to blame the Congress? Is four/five years enough time for the party in power to prove itself?

Given the slow speed of the Indian state machinary any project typically takes a long time to be planned and completed. Especially if the project spans multiple states (like the National Highway Project).

Take the Delhi Metro Project for example: The plan for the metro was passed, guess when? Maybe you thought 1980s or 1990s? No way! The concept of the metro was finalised in the 1960 Delhi Master Plan. The legal framework was setup in 1978 (the Metro Railways (Construction of Works) Act) (see this). When did the construction start? 1998. I guess that is why the Metro project is considered to be a miracle.

In my view each Government should be given at least a 6-8 years period to plan and implement projects before cursing them. We have seen how bad governments are when it comes to handing over and giving credit.

The situation is even worse when it comes to State-level projects. Uttar Pradesh is famous for this. Key infrastructure projects stop and start based on which Government is in power.

Then what is the fight and posturing about? Can any Government claim that they are the masterminds behind development projects when each major project has its roots in history? I don’t think so.

I think we should be honest with ourselves and evaluate the parties based on what NEW things they did. What new initiatives were put in place? We should never go by the chest-thumping and shouting as politicians try and take credit.

 

 

 

 

 

Hulla of Indian Elections!

The movie Hulla (2008) talks about how noise leads to a man loosing his peace and stability.

Indian politicians seem to be trying to do the same to the masses. Trying to confuse the people with noise so that they loose their capacity to think and vote. This ensures that the real issues get clouded in the noise.

Which ever channel you turn to, whatever election issue may it be (from Terrorism to Economic Slowdown) the discussion starts out quite calmly with the various people from different parties (the standard on NDTV being BJP, Congress and the Left) looking all cool and calm.

The anchor introduces the people and the topic.

Then the anchor puts the first question to one of the representatives. That is when the whole group of ‘politicians’ starts shouting at one another like a couple of sulking teenagers.

Usually it is the party in power vs party wanting to be in power which, sometimes, is almost the same as party in power vs party which WAS in power 5 years ago!

What we see is discussions on all issues, big or small, reduce to a shouting match with the anchor trying to guide the discussion. The attempt to guide is as affective trying to divert a flood with a straw!

All the noise, all the fighting, all the personal and political battles being fought on air while the real issues are being ignored. No one is going to admit failing and no one is going to give an inch.

What happens then? A stalemate. No discussion and no one party either gets questioned by the public or needs to defend itself.

I wonder if this is something that all sides have implicitly agreed on. To create a noise screen to drown out the REAL questions.

INDIA! WEAR EARPLUGS AND TRUST YOUR EYES!

 

 

Dealing with Job Consultants in UK (Part 3: Remaining Stages)

Part 1: Here
Part 2: Here
Part 3: Here

IMPORTANT ADVICE IS IN ITALICS

There are several stages (as mentioned before):

1) The Initial Call

2) Pre-interview Phase

3) Post-interview Phase

4) Finalization Phase

5) Bye-bye!

 The Pre-interview Phase

If the client likes your CV the consultant will contact you to arrange an interview date. Most companies reimburse rail ticket costs especially if the interview is in London. Make sure, before you select a date and time, you confirm whether your travel expenses will be reimbursed. Also find out the duration of the interview so that you can plan your return journey. This is especially important if you are working.

The consultant will also send you a detailed interview description and call you up to find out if you are all set for the interview. Make sure you know the location of the company and other logistic details.

Make sure you cover all the points and if you are at all confused by anything related to the interview (from the nature of the interview to what kinds of clothes you should wear), don’t feel shy and ask the consultant!

The consultant might want to meet with you before the interview. Try and meet as this may allow the consultant to give you some important tips before the interview.

The Post-interview Phase

The consultant will surely call you after the interview is over to discuss with you how it went and what you thought of the company. Make sure you are honest. Sometimes a consultant might be able to get you through to the next round if they have some influence with the company.

This is the second most important phase. Here most consultants change sides. Now they will push you hard to accept the job, provided obviously that you clear all the interviews (especially if there are mutliple rounds of interviews). Make sure that you are comfortable with the job and the company.

Most probably you would have visited the offices of the prospective employer and seen the work environment during the interview. By now you should have a good idea of whether this is the way ahead for your career or not.

Be very clear and honest with the consultant. Don’t come under pressure and remember your consultant will show you the positive side of taking up the job. You have to find out the negatives and balance it out with the positives to ensure it is the right move for you!

If you are confused TAKE SOME TIME TO THINK ABOUT THE JOB OFFER!

Every consultant will give you time to think but just remember that most consultants will expect a definitive yes or no afterwards.

 

Finalization Phase and Bye-bye!

If you accept the offer the consultant will keep you updated as to what is required next. There might be some paperwork or a meeting with the employer and consultant. This is usually the shortest phase and the consultant’s work is almost done.

Most consultants remain in touch at least till you start at the new place. They might get in touch later if there are any issues or just to take feedback from you about the job and to find out if all is going well.