Javascript XMLHTTPRequest Problem

M

mauroalberti

Hello everyone,

I'm currently trying to add some AJAX functionality to the tree2
JSF-component from the Apache MyFaces project (i. e. if the user clicks
on some node of the tree component, then not the whole tree is to be
rendered again but just the part of the tree which has actually
changed).

Using Mozilla as browser everything works fine, but if IE is used I'm
facing the following problem:

If I click on the [-] box next to an expanded node, nothing happens (of
course, normally the node should be closed) - however, there is a
single node being displayed by the component where it actually works
(it is always the same node, independant of the order in which this
node respectively the other ones are expanded and closed - very strange
behaviour...)


This is the AJAX part of the code on my JSP page:

<script type="text/javascript">
<!--
var clickedNodeID;

var req;

function ajaxtest(treenodeid){

//req = null;

if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}

if (req.readyState != 0) {
req.abort();
}


clickedNodeID = treenodeid;

var url = "webdeskAjax.faces?clickedNodeID="+ treenodeid;

// send request to the server
if (req != null) {
req.open("GET", url, true);
req.onreadystatechange = processAjaxTreeResponse;
req.send(null);
}

}

function processAjaxTreeResponse() {
if (req.readyState == 4){
//process only if OK
if (req.status == 200) {
if(req.responseText==null) {
hidePopup();
}
else {
parseAjaxResponse(req.responseText);

}
}
}


}


function parseAjaxResponse(result){


var divnode = document.getElementById(clickedNodeID + ":divid");

divnode.innerHTML = result;

alert(result);


}


//-->
</script>


The variables req and clickedNodeID contain the XMLHTTPRequest object
respevtively the ID of the node which has been lastly clicked.

The parseAjaxResponse method determines a certain div element and adds
the content being sent from the server to this element.

The alert statement has been added merely for testing purposes (as my
MS-Debugger crashes every time I'm trying to move a single step
further- anyone in here made similar experiences with the
application???): every time I click on the [-] box the content that is
added to the div element is equal to the content that has been saved in
the element before the user action. The point is, that the server has
not been contacted (I've registered a PhaseListener to my FacesContext)
so I absolutely do not know where the content comes from...

Anyone got any advice what could be the reason for that odd behavior??

Thanks a lot,

Alex
 
T

TheBagbournes

mauroalberti said:
The point is, that the server has
not been contacted (I've registered a PhaseListener to my FacesContext)
so I absolutely do not know where the content comes from...

I had a similar problem with IE. It was caching responses from
XMLHttpRequests. Try making

var url = "webdeskAjax.faces?clickedNodeID="+ treenodeid;

into

var url = "webdeskAjax.faces?clickedNodeID=" + treenodeid +
"&requestid=" + (new Date()).getTime();


Nige
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top