我是 Liferay 的初学者,我想进行 ajax 调用。我正在做的是: - 我在 jsp 页面中有一个按钮,以使 ajax 调用一个变量在 javascript 代码中初始化,并在每次用户单击按钮时递增。这个变量被转换到服务器以用作函数的参数。
代码片段
aui_ajax.jsp:
<input type="button" value = "Ajouter un projet" onClick="<portlet:namespace/>Test();return false;">
<div id="usersTable">
<input type="button" value = "Ajouter un projet" onClick=" <portlet:namespace/>Test();return false;">
</div>
<div id="wait" style="display:none; width: 69px; height: 89px; border: 1px solid black; position: absolute; top: 50%; left: 50%; padding: 2px;">
<img src='http://www.w3schools.com/jquery/demo_wait.gif' width="64" height="64" /> <br>Loading..
</div>
<script>
var i=1
function <portlet:namespace/>Test() {
var i=1;
AUI().use('aui-base','aui-io-request', function(A){
i++;
A.one('#wait').setStyle('display', 'block');
var allRows=A.one('#usersTable').getHTML();
var querystring = 'message:' + '1';
//aui ajax call to get updated content
A.io.request('<%=updaContentURL%>',{
dataType: 'json',
method: 'GET',
data: querystring,
on: {
success: function() {
var data=this.get('responseData');
A.Array.each(data, function(obj, idx){
var tableRow=obj.firstName;
//allRows=allRows.trim()+tableRow.trim();
//A.one('#usersTable').empty();
//A.one('#usersTable').setHTML(tableRow.trim());
A.one('#usersTable').append(tableRow.trim());
A.one('#wait').setStyle('display','none');
});
}
}
});
});
}
</script>
ContentAutoUpdateAction.java
public class ContentAutoUpdateAction extends MVCPortlet {
public void serveResource(ResourceRequest resourceRequest,
ResourceResponse resourceResponse)
throws IOException, PortletException {
try {
System.out.println("====serveResource========");
JSONObject jsonUser=null;
JSONArray usersJsonArray=JSONFactoryUtil.createJSONArray();
resourceRequest.getParameter("message");
int i=Integer.parseInt(message);
i++;
System.out.println(i);
//}
PrintWriter out=resourceResponse.getWriter();
System.out.println(usersJsonArray.toString());
out.print(usersJsonArray.toString());
}
catch (Exception e) {
e.printStackTrace();
}
}
问题是我无法在 ContentAutoUpdateAction.java 中获取参数“message”