javascript端代码
$(document).ready(function(){
var myArray = {"optinh":["header","para1","para2","sendotp","cancel","help","footertext"]};
var jsonObj = JSON.stringify(myArray);
$.ajax({
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
url: "http://raija04-i140720:8081/vpas/resources/CapDetailService/Strings",
data: jsonObj,
type: "POST",
dataType:'json',
success: function (data) {
// var obj = $.parseJSON(data);
for (var key in data) {
alert(data[key]);
}
$('#header').html(data["header"]);
$('#para1').html(data["para1"]);
$('#para2').html(data["para2"]);
$('#sendotp').html(data["sendotp"]);
$('#cancel').html(data["cancel"]);
$('#help').html(data["help"]);
$('#footertext').html(data["footertext"]);
},
error:function(data,status,er) {
alert("error: "+data+" status: "+status+" er:"+er);
},
});
}
和使用ajax调用
调用的webservice代码 @POST
@Path("/Strings")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Object getStrings(/*@QueryParam("user")*/ Util1 jsonObj) { code here
}
Web服务的Object Mapper类
@XmlRootElement
public class Util1 {
List<String> optinh = new ArrayList<String>();
public List<String> getOptinh() {
return optinh;
}
public void setOptinh(List<String> optinh) {
this.optinh = optinh;
}
}
面对UnSupported媒体类型错误
POST http://raija04-i140720:8081/vpas/resources/CapDetailService/Strings 415(不支持的媒体类型)