tags:

views:

14

answers:

1

i hava created the ajax XMLHttpRequest request for getting the data dyanmically ,

here is the code

var XMLHttpReq;

function createXMLHttpRequest() { if (window.XMLHttpRequest) { XMLHttpReq = new XMLHttpRequest(); } else { if (window.ActiveXObject) { try { if(XMLHttpReq==null) XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");

        }
        catch (e) {
            try {
                if(XMLHttpReq==null)
                XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
            }
        }
    }
}

}

this is the method which sends the request

function personList(person) {

createXMLHttpRequest();
var url="query?option=person&userName="+person.innerHTML;
XMLHttpReq.open("GET", url, true);
XMLHttpReq.onreadystatechange =personListResponse;
XMLHttpReq.send(null); 
}

function personListResponse() {
if (XMLHttpReq.readyState == 4) { 
    if (XMLHttpReq.status == 200) {
    var xml=XMLHttpReq.responseXML;
    }
}

}

the request is sent to the servlet only for the first time,when i try for the second the request is not sent ,instead am getting the previous response what i got earlier

+1  A: 

I suppose it's cache. Try adding this before the request:

XMLHttpReq.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
XMLHttpReq.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
XMLHttpReq.setRequestHeader("Pragma", "no-cache");

If it doesn't work, try adding an additional parameter to your url, making it unique and therefore, not caching.

var url="query?option=person&userName="+person.innerHTML + "&d=" + new Date().getTime()

I really don't like this solution, but it helps you to know if the problem is related to cache.

Guilherme Oenning
i have added the following line of code response.setHeader("Cache-Control", "no-cache") it worked for me
Lalchand