I have no much time to read your code, but I would like give you suggestions. It's much easier to use AJAX library ( such as jQuery) to do an AJAX application.
And since you're using Python, I think it's easier to use JSON to instead of XML. 2009/4/16 DiveIntoGAE <[email protected]> > > when i change the customerId select, the departmentId select and the > contactorName Select will also change,but the following code can't do > that.can anybody points out the problem? > The code is belowing: > > ------------------------------------------------------------------------------------- > <script type="text/javascript"> > var xmlHttp; > function createXMLHttpRequest() { > if (window.ActiveXObject) { > xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); > } > else if (window.XMLHttpRequest) { > xmlHttp = new XMLHttpRequest(); > } > } > function refreshDeptAndContacList() { > var companyId = document.getElementById > ("companyId").value; > if(companyId == "") { > clearDepartmentsList(); > return; > } > var url = "getDeptsOfCustomer?companyId="+ companyId; > createXMLHttpRequest(); > xmlHttp.onreadystatechange = handleStateChange; > xmlHttp.open("GET", url, true); > xmlHttp.send(null); > } > function handleStateChange() { > if(xmlHttp.readyState == 4) { > if(xmlHttp.status == 200) { > updateDepartmentsList(); > } > } > } > function updateDepartmentsList() {alert > (xmlHttp.responseXML.getElementsByTagName("department")); > clearDepartmentsList(); > var departments = document.getElementById("departmentId"); > var resultsOfDept = > xmlHttp.responseXML.getElementsByTagName("department"); > var optionOfDept = null; > for(var i = 0; i < resultsOfDept.length; i++) { > optionOfDept = document.createElement("option"); > optionOfDept.appendChild(document.createTextNode > (resultsOfDept[i].firstChild.nodeValue)); > departments.appendChild(optionOfDept); > } > > var contactorNames = document.getElementById > ("contactorName"); > var resultsOfContac = > xmlHttp.responseXML.getElementsByTagName("contactorName"); > var optionOfContac = null; > for(var i = 0; i < resultsOfContac.length; i++) { > optionOfContac = document.createElement("option"); > optionOfContac.appendChild(document.createTextNode > (resultsOfContac[i].firstChild.nodeValue)); > contactorNames.appendChild(optionOfContac); > } > } > function clearDepartmentsList() { > var departments = document.getElementById("departmentId"); > while(departments.childNodes.length > 0) { > departments.removeChild(departments.childNodes[0]); > } > var contactorNames = document.getElementById > ("contactorName"); > while(contactorNames.childNodes.length > 0) { > contactorNames.removeChild(contactorNames.childNodes > [0]); > } > } > </script> > > ----------------------------------------------------------------------------------------------------- > <SELECT onchange="refreshDeptAndContacList();" size=1 id='companyId' > name='companyId' style="width:100%"> > <OPTION value=""> </OPTION> > {% for company in queryCompanyList %} > <OPTION value={{ company.CUSTOMER_ID }} > >{{ company.COMPANY_NAME }}</OPTION> > {% endfor %} > </SELECT> > > <SELECT size=1 id='departmentId' name=departmentId style="width:200px" > onchange=""> > > </SELECT> > <SELECT size=1 id='contactorName' name=contactorName style="width: > 100%" onchange=""> > > </SELECT> > > ---------------------------------------------------------------------------------------------------------------------------------------------------- > class GetDeptsOfCustomer(webapp.RequestHandler): > def get(self): > self.response.headers['ContentType'] = "text ml;charset=UTF-8" > companyId = self.request.get('companyId','1101') > queryDeptList = db.GqlQuery("SELECT * FROM M_CUSTOMERS_DEPT > WHERE CUSTOMER_ID = :1 ORDER BY DEPT_ID", companyId) > results = "<companys>" > for dept in queryDeptList: > results += "<department>" > results += dept.DEPT_NAME > results += "</department>" > > results += "<contactorName>" > results += dept.PERSON_IN_CHARGE > results += "</contactorName>" > results += "</companys>" > self.response.headers['ContentType'] = "text/xml" > self.response.out.write(results) > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---
