In my application inorder to avoid duplicate Group names Im trying to validate user entered value through AJAX call. But im not receiving expected responseText but im receiving responseText from cache. JS file: try{ if (window.ActiveXObject) //IE var xhr = new ActiveXObject("Microsoft.XMLHTTP"); else if (window.XMLHttpRequest) //other var xhr = new XMLHttpRequest(); else alert("your browser does not support AJAX"); }catch(e){alert("error in creting xmlhttpresponse: "+e);}
escName= document.forms(0).txtEscalationName.value;
escId = document.forms(0).hidGroupId.value;
urlParam = "escName=" +escName +"&escCode=" +escId;
alert(".."+urlParam);
xhr.open("GET", "/myapp/jsp/main/escalationNameCheck.jsp?"+urlParam+"&ran="+Math.random() ,true);
xhr.setRequestHeader("Cache-Control","no-cache");
xhr.setRequestHeader("Pragma","no-cache");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4)
{
if (xhr.status == 200)
{
if (xhr.responseText != null)
{
alert(document.getElementById("escalationNameValidate"));
try{
var populate = document.getElementById("escalationNameValidate");
populate.innerHTML = xhr.responseText;
}catch(e){
alert("ERROR!...."+e);
}
}
else
{
alert("Failed to receive JSP file from the server - file not found.");
return false;
}
}
else
alert("Error code " + xhr.status + " received: " + xhr.statusText);
} else
alert("not ready");
}
xhr.send(null);
After referring here: responseText - XMLHttpRequest
I have tried mentioning event like below but it gave exception saying target is null or not an object.
xhr.onreadystatechange = function(event) {
var xhr = event.target;
if (xhr.readyState == 4)
{ alert("first if");
if (xhr.status == 200)
{alert("second if");
if (xhr.responseText != null)
{alert("third if"+xhr.responseText);
alert(document.getElementById("escalationNameValidate"));
try{
var populate = document.getElementById("escalationNameValidate");
alert("11");
alert("pop.."+populate.innerHTML);
populate.innerHTML = xhr.responseText;
}catch(e){
alert("ERROR!.xhr..."+e);
}
}
else
{
alert("Failed to receive JSP file from the server - file not found.");
return false;
}
alert("escNameDuplicate"+document.getElementById("escNameDuplicate"));
}
else
alert("Error code " + xhr.status + " received: " + xhr.statusText);
} else
alert("not ready");
}
So I tried 1. giving cache-control as no-cache in requestHeader 2. Making xhr as local variable by using var xhr while defining it. 3. pointed the event-instance in onreadystatechange function also. Browser version: IE7
Kindly assist. Regards, Nidhya