Calling an action using Ajax URL in Struts 2

后端 未结 1 1616
执念已碎
执念已碎 2020-12-10 18:53

I am trying to connect to my action class by using URL as below in Ajax. But its not going into my action class and even it is not showing the selected value by using

相关标签:
1条回答
  • 2020-12-10 19:41

    To map an action to the method you should do something like

    <action name="selectstate" class="com.thirdtask.actions.SelectAction" method="selectstate">
      <result>/selecttag.jsp</result> 
    </action>
    

    action name should be without action extension and result by default is named "success", the path to JSP should be absolute here.

    Calling ajax

    $.ajax({
        type : "GET",
        url  : "<s:url action='selectstate'/>",
        dataType : 'text/javascript',
        data : {'name' : $("#selectedCountry").text()},
        success : function(result){
          if (result != null && result.length > 0){
            $("statesdivid").html(result);
          }
        },
        error : function(xhr, errmsg) {alert("No values found..!!");}
    });         
    
    0 讨论(0)
提交回复
热议问题