I'm currently working on a school project which consists of developing a game using Struts2/JSP.
The problem I have is I can't get Data from my ActionClass to my JSP using jQuery. It works great the other way and I found multiple sources to do so.
Here is my minimized GameAction.class
:
private String playerColor;
private Map<String,Object> applicationMap;
public String execute (){
playerColor = ((Joueur)applicationMap.get("joueur")).getPlayerColor();
return SUCCESS;
}
NOTE: everything has a getter/setter.
game.js
:
var $playerColor;
$(window).on('load', function () {
$.ajax({
type : "GET",
url : "gotoGameAction",
data : "playerColor=",
success : function (data) {
$playerColor = data;
var html = "<h2>" + $playerColor.toString() + "</h2>";
$("#playerColor").html(html);
}
})
});
Struts.xml
:
<package name="default" extends="json-default" namespace="/">
<action name="gotoGameAction" class="actions.logins.GameAction">
<result name="success" type="json">/WEB-INF/views/game.jsp</result>
</action>
</package>
This output I have on my JSP is : [object Object]
.
I really can't get what's going on there.