这是我的Ajax调用:Spring MVC的返回简单的文本,而不是JSON在使用Ajax调用
$.ajax({
url: 'configuration/activePlatform/',
type: 'GET',
dataType: 'json',
contentType: "application/json",
success: function(data){
console.log("getActivePlatform ACK");
$('#activePlatform').append(data);
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
从这一呼吁的响应是200 OK。
我得到一个明确的文本作为输入反应,错误味精是“意外令牌的”
这是我的服务器端代码:
@Controller
@RequestMapping("/configuration")
public class configuration {
@Autowired
public CommonConfigurations configurations;
@RequestMapping(value = "/activePlatform", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON)
public @ResponseBody
String activePlatform() throws Exception {
return configurations.activePlatform;
}
}
我做了什么错?
问题是,这只是当我返回一个例子CommonConfigurations类对象,当我返回一个字符串,我把它作为纯文本,而不是在JSON格式 – USer22999299
为什么你需要一个字符串消息,你能解释一下你的问题有点.. –
我想返回的值 - “沙盒”或“生产”作为JSON格式的字符串。 – USer22999299