JS:
<SCRIPT> var xhr = ajaxxmlhttprequest (); function getsups () {If (xhr = NULL) {alert ('ajax not supported by browsers '); return;} xhr. onreadystatechange = statechanged; var url = "supliers. do? Method = getallsup "; xhr. open ("Post", URL, true); xhr. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded");} function statechanged () {// alert ("test"); If (xhr. readystate = 4) {document. getelementbyid ("Sup "). innerhtml = xhr. responsetext; return ;}} function ajaxxmlhttprequest () {var XMLHTTP; try {// Firefox, opera 8.0 +, Safari XMLHTTP = new XMLHttpRequest ();} catch (E) {// Internet Explorer try {XM Lhttp = new activexobject ("msxml2.xmlhttp");} catch (e) {try {XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");} catch (e) {alert (" your browser does not support Ajax! "); Return false ;}}return XMLHTTP ;}</SCRIPT>
Java code
public ActionForward getSups(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { List<Supplier> rlist = this.supServices.getAllSupp(); String beg1 = "<option value= "; String beg2=">"; String end = "</option>"; for(Supplier sup:rlist){ beg1+=sup.getS_id(); beg1+=beg2; beg1+=sup.getSupplier_name(); beg1+=end; } PrintWriter pw = response.getWriter(); pw.write(beg1); return null; }