我试图了解如何使用JSON,在此过程中,我试图从Struts2操作获取JSON响应并显示响应警报。为此,我在JavaScript中使用Ajax

POST,如下所示:

function checkButtonClick(id){

var btnSave = 'saveAttendees';

var atNameList = $('#attName'+id).val();

var ptNameList = $('#postName'+id).val();

var aId = $('#at_id'+id).val();

alert("here");

var arr = {buttonName: btnSave,

attendeesNameList: atNameList,

attendeesPostList: ptNameList,

hidden_At_id: aId

};

$.ajax({

data: arr,

type: 'POST',

dataType: 'json',

url:"meeting_record_form",

success:function(result){

alert(result.myMsg);

},

error:function(result){

alert("error");

}

});

}

我的动作类包含一个String字段,我试图将其作为JSON响应显示在警报中。但是我发现这样做有问题。我想念什么或做错什么?

我的动作课如下:

private String myMsg;

public String getMyMsg() {

return myMsg;

}

public void setMyMsg(String myMsg) {

this.myMsg = myMsg;

}

private String updateAttendeesRecord() {

meetingRecordService.updateAttendeesRecord(attendeesListMethod(), meeting_record);

setMyMsg("Update Successful!");

return SUCCESS;

}

struts.xml 文件:

我的pom.xml:

org.apache.struts

struts2-json-plugin

2.3.15

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐