/    Sign up×
Community /Pin to ProfileBookmark

Javascript XMLHTTPRequest Problem

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

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@mauroalbertiauthorMar 03.2006 — [I]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...)[/I]

OK, forget about this - today not a single of the nodes responds to the click on the [-] box...
×

Success!

Help @mauroalberti spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...