如何使用Ajax调用Java Action [英] How to call Java Action using ajax

查看:60
本文介绍了如何使用Ajax调用Java Action的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是AJAX的新手.我在JSP中有两个下拉列表,基于从第一个下拉列表中选择一个值的情况,我需要在后端的第二个下拉列表中填充值. 我试图通过 struct1.2 中的AJAX执行上述功能.

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.

我在onChangePrdGrp [ JavaScript函数]中使用了以下代码:

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:

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:[需要在此DropDown中填充值]

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>

请在这方面建议我.

推荐答案

使用jQuery非常简单

It is very simple if you use jQuery

请参见此处

这里给出了很好的例子.记住要插入与jQuery相关的js文件

Here they give good example.Remember to insert jQuery related js 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>

这篇关于如何使用Ajax调用Java Action的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆