开发者

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 val开发者_JS百科ue 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.

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

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.


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).

All you need to make it work is:

  • What URL you need to call the Struts action
  • How to make the call to the Struts action
  • How to change the contents of a div element using Javascript

Some helpful Google hits: Struts and Ajax Working Together, Changing content on the fly using Javascript.

You have the right direction, now go and make the final touches.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜