Wednesday, August 25, 2010

Solution for the error while setting session using javascript

I was working on setting projectid into session using javascript.

where I was using below code
if (projectid) {

// URL to get states for a given country
CreateXmlHttp();
// If browser supports XMLHTTPRequest object
if (XmlHttp) {
var requestUrl = "AJAXServlet.aspx?projectid=" + projectid + "";
//Initializes the request object with GET (METHOD of posting),
//Request URL and sets the request as asynchronous.
XmlHttp.open("GET", requestUrl, true);
//Setting the event handler for the response
XmlHttp.onreadystatechange = HandleResponse;
//Sends the request to server
XmlHttp.send(null);
}
else {alert("Unable to populate project session");
}
}
 
which was populating on click of list of projects with radio button, but it was working only for 2 clicks, after that If I select any other project session was not populating, but I was getting correct response message with XmlHttp.status = 200.
 
I sat to fix this for about 2 hours, but I didnot find any issue with ajax code.
 
Then, just for testing I append random number to the url, surpricingly it started working properly,
 
below is the change I have made
var rand_no = Math.random();
var requestUrl = "AJAXServlet.aspx?projectid=" + projectid + "&ran= "+ rand_no +"";
 

Friday, August 20, 2010

SQL query "when Null" will not work

SQL query Null will not work for the below case
select case amount when null then 0 else amount end from [Table]

Change this as below, this will work
select case when Amount is null then 0 else amount end from [Table]