Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Internet Explorer XMLHTTPRequest problem

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).


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 + " ivid");

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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try removing this:



and

change this:


to



and good idea to do


Eric
 
Alexander D�ubler
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've changed the code as shown below but I still encounter the same behavior...


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

var req;

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

function ajaxtest(treenodeid){

clickedNodeID = treenodeid;

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

// send request to the server
if (req) {
req.open("GET", url, true);
req.onreadystatechange = processAjaxTreeResponse;
req.send(null);
}
else{
alert("Ajax is not supported");
}

}

function processAjaxTreeResponse() {
if (req.readyState == 4){
//process only if OK
if (req.status == 200){
if(req){
parseAjaxResponse(req.responseText);
}
else{
alert("Ajax is not supported");
}
}
}
}


function parseAjaxResponse(result){

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

divnode.innerHTML = result;

alert(result);

}
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran this with no problem:



You should really think about restructuring it to look more like this:



Now your calls will not have problems with clicking multiple requests, which I think that abort() was trying to fix in your first posting.
(When you post in the future use code tags and click the disable smiles checkbox!]

Eric
 
    Bookmark Topic Watch Topic
  • New Topic