Categories | Question details Back To List | ||
Loading XMl from responseText ajax. I have generated XMLString at server and sending the response back through response.getwriter().write(xmlstring); now I want to loaad this xmlstring in grid. Please help. I tried all the method available for loadingXML. this is my client side code.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <link rel= "STYLESHEET" type="text/css" href="jsp/dhtmlxgrid.css"><script src= "jsp/dhtmlxcommon.js"></script><script src= "jsp/dhtmlxgrid.js"></script><script src= "jsp/dhtmlxgridcell.js"></script><script src= "jsp/dhtmlxgrid_srnd.js"></script><script src= "jsp/dhtmlxgrid_nxml.js"></script><script src= "jsp/dhtmlxcommon_debug.js"></script><script> function getXMLObject() //XML OBJECT{ var xmlHttp = false; try {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") // For Microsoft IE 6.0+} catch (e2) {xmlHttp = false // No Browser accepts the XMLHTTP Object then false} if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera Browsers} return xmlHttp; // Mandatory Statement returning the ajax object created} var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax objectfunction ajaxFunction() { var getdate = new Date(); //Used to prevent caching during ajax call var param = createQueryString(); var url = "myAction.do?action=showGrid&"+param; if(xmlhttp) {xmlhttp.open( "GET",url,true); //MyServ is the servlet urlxmlhttp.onreadystatechange = handleServerResponse ; xmlhttp.setRequestHeader( 'Content-Type','application/x-www-form-urlencoded'); //alert(name);xmlhttp.send(param); } } function createQueryString() { var Name = document.getElementById("name").value; var EmpId = document.getElementById("empid").value; var Location = document.getElementById("location").value; var param = "name=" + Name + "&empid=" + EmpId+ "&location=" + Location; return param;} function handleServerResponse() { if ((xmlhttp.readyState == 4)&&(xmlhttp.status==200)) { var xml = xmlhttp.responseText;alert(xml); //doInitGrid();var mygrid;//function doInitGrid(){
mygrid = new dhtmlXGridObject("mygrid_container");mygrid.setImagePath( "jsp/codebase/imgs/");mygrid.setHeader( "Name,EmpId,Location");mygrid.setInitWidths( "*,100,100");mygrid.setColAlign( "center,center,center");mygrid.setSkin( "light");mygrid.setColSorting( "int,str,str");mygrid.init(); //mygrid.enableSmartRendering(true,50); mygrid.load(xml); } // else { // alert("Error during AJAX call. Please try again"); // }} </script> </head>
<!--<body onload= "doInitGrid();">--><body> <form method= "post" name="form0"><table id= "mytable" border=1 size=50% align="center" BGColor="#C0C0C0"><tr> <td>Name:</td> <td>Emp Id:</td> <td>Location:</td> <!--<td>Salary:</td> <td>Designation:</td> <td>Skills:</td> <td>Qualification:</td>--> </tr> <tr> <td><input type = "text" id="name"/></td><td><input type = "text" id="empid"/></td><td><input type = "text" id="location"/></td><!--<td><input type = "text" id="salary"/></td><td><input type = "text" id="designation"/></td><td><input type = "text" id="skills"/></td><td><input type = "text" id="qualification"/></td>--></tr> <tr> <td><input type = "button" id="enter" value="Send Dynamic Request" onclick="ajaxFunction()"/></td></tr></table> </body> <div id= "mygrid_container" style="width:700px;height:300px;" ></div><html> Answer posted by dhxSupport on Apr 01, 2009 03:46 Try to use mygrid.parse(xml) method instead of load(). Please see more information about loading data in grid here http://dhtmlx.com/docs/products/dhtmlxGrid/doc/articles/Loading_data_in_grid.html#grid_art_loadingdata |