我无法在 Liferay6.1 中使用 Jquery Ajax 调用 Struts2 Action
请查看以下文件,我粘贴在下面,如果这不是打电话的方式,请告诉我
Jsp页面
<portlet:renderURL var="getChartData" windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>">
<portlet:param name="struts_action" value="/getChartData" />
</portlet:renderURL>
<script type="text/javascript">
$(document).ready(function(){
alert('jjjj');
$.ajax({
type : 'POST',
url : '<%=getChartData%>',
data: "countryId="+countryId,
success : function(data){
alert(data);
}
});
});
</script>
struts.xml
<action name="getChartData" class="com.actions.ImageDisplayAction" method="getChartData">
<result name="success">/WEB-INF/view/blank.jsp</result>
</action>
portlet.xml
<portlet>
<portlet-name>DisplayImages</portlet-name>
<display-name>DisplayImages</display-name>
<portlet-class>org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher</portlet-class>
动作类
public class ImageDisplayAction extends ActionSupport {
public String getChartData() {
System.out.println("Hi ");
System.out.println("Hi ");
System.out.println("Hi ");
System.out.println("Hi ");
return SUCCESS;
}
}
更新部分:
我没有收到任何异常,这是我完整的 struts.xml 文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.multipart.saveDir" value="D:\\ant" />
<package name="view" extends="struts-portlet-default">
<action name="index" >
<result name="input">/WEB-INF/view/index.jsp</result>
<result name="success">/WEB-INF/view/index.jsp</result>
</action>
<action name="getChartData" class="com.actions.ImageDisplayAction" method="getChartData">
<result name="success">/WEB-INF/view/blank.jsp</result>
</action>
</package>
</struts>
这是在我的 JSP 文件中(没有 chnages )
<portlet:renderURL var="getChartData" windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>">
<portlet:param name="struts_action" value="/getChartData" />
</portlet:renderURL>
<script type="text/javascript">
$(document).ready(function(){
alert('jjjj');
$.ajax({
type : 'POST',
url : '<%=getChartData%>',
data: "countryId="+countryId,
success : function(data){
alert(data);
}
});
});
</script>