简体   繁体   English

从 struts2 调用 ajax 来填充 div

[英]Calling ajax from struts2 to populate a div

I have a drop down and have a JavaScript function tied to the onchange event of the drop down.I need to call a action class with the drop down selected value and fetch data from database.I need pointers to call the action class from JavaScript and also pass the selected value of drop down to fire a DB select query and update a table present in a div withou refreshing the whole page. I have a drop down and have a JavaScript function tied to the onchange event of the drop down.I need to call a action class with the drop down selected value and fetch data from database.I need pointers to call the action class from JavaScript and还传递下拉的选定值以触发 DB select 查询并更新 div 中存在的表而不刷新整个页面。

My drop down我的下拉

<s:select name="newQuestion.CertificationId" list="certificationList"
    listKey="certificationId" listValue="certificationName" headerKey=""
    headerValue="Select Certification" label="Certification Name"
    onchange="getQuestionsList(this.value)" />

Javascript function Javascript function

function getQuestionsList(val) {
        alert("Here" + val);



    }

Basically for each of the drop down selected values I need a ajax call to DB to populate a div which is hidden currently.基本上,对于每个下拉选择的值,我需要对 DB 调用 ajax 来填充当前隐藏的 div。

What exactly is it you need assistance with?你到底需要什么帮助? From what I understand, you have it all figured out (minus the ajax call to the Struts action).据我了解,您已经弄清楚了(减去对 Struts 操作的 ajax 调用)。

All you need to make it work is:让它发挥作用所需要做的就是:

  • What URL you need to call the Struts action你需要什么 URL 调用 Struts 动作
  • How to make the call to the Struts action如何调用 Struts 动作
  • How to change the contents of a div element using Javascript如何使用 Javascript 更改 div 元素的内容

Some helpful Google hits: Struts and Ajax Working Together , Changing content on the fly using Javascript .一些有用的谷歌点击: Struts 和 Ajax 一起工作使用 Javascript 即时更改内容

You have the right direction, now go and make the final touches.你有正确的方向,现在 go 并进行最后的润色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM