How to call Java Action using ajax

跟風遠走 提交于 2019-12-25 03:53:31

问题


I am new to AJAX. I am having two drop drop list in JSP, based on selecting one value from first drop down, I need to populate values in second drop down list from Back End. I have tried to do the above functionality from AJAX in struct1.2.

I have used following Code inside onChangePrdGrp[JavaScript Function]:

var prdGrp = document.getElementById('strProductGroup').value;
if("" != prdGrp){
    var xmlhttp;

    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    document.getElementById('prdPitch').style.display = "block";
    document.forms[0].module.value= "getProductPicthed";
    xmlhttp.open("POST","/lmsGetPrdPitched.do?prdGrp="+prdGrp,true);
    xmlhttp.send();
}else{
    document.getElementById('prdPitch').style.display = "none";
    document.getElementById('strProductPitched').value = "";
    document.getElementById('strProduct').value = "";
}

DropDown1:

<tr>
<td style="text-align: left" width="20%">Product Group</td>
<td style="text-align: left" width="20%"><html:select
property="strProductGroup" style="width:180px;"
onchange="onChangePrdGrp()">
<html:option value="">select</html:option>
<html:optionsCollection name="ProdGrpList" />
</html:select></td>
</tr>

DropDown 2: [Need to Populate values in this DropDown]

<tr id="prdPitch">
     <td style="text-align: left" width="20%">Product Pitched</td>
     <td style="text-align: left" width="20%"><html:select
      property="strProductPitched" style="width:180px;">
      <html:option value="">select</html:option>
      <%if(null != ProductPitchList) { %>
      <html:optionsCollection name="ProductPitchList" />
      <%} %>
      </html:select></td>
</tr>

Please suggest me on this.


回答1:


It is very simple if you use jQuery

see here for example

Here they give good example.Remember to insert jQuery related js files

include following files

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>


来源:https://stackoverflow.com/questions/15499629/how-to-call-java-action-using-ajax

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!