這是我的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