我想從我的控制器string response
但我得到下面的錯誤:爪哇 - 字符串@ResponseBody - 錯誤200
SyntaxError: Unexpected end of JSON input(…) "Error 200"
當我變成一個布爾值或不同類型的反應,這是工作正常。問題是當我嘗試返回一個字符串。
JS代碼:
$.ajax({
method: "POST",
url: "./signup",
data: _data,
dataType: "json",
contentType : "application/json;charset=UTF-8",
success : function(data) {
console.log(data)
},
error : function(qXHR, textStatus, errorThrown){
console.log(errorThrown, "Error " + qXHR.status);
}
});
控制器代碼:
@RequestMapping(value = "/signup", method = RequestMethod.POST, produces = {"text/plain", "application/*"})
public @ResponseBody String signup(@RequestBody UserSignup details) {
//...
return message;
}
任何想法我怎麼能解決這個問題?我已經嘗試了一些東西,但沒有任何工作。我認爲響應格式是錯誤的,因爲代碼的期望。
編輯
我已經改變了我的代碼(刪除produces
),但我仍然得到同樣的錯誤:
SyntaxError: Unexpected end of JSON input(…) "Error 200"
@RequestMapping(value = "/signup", method = RequestMethod.POST)
public @ResponseBody String signup(@RequestBody UserSignup details) {
message = "ok";
}
return message;
}
我曾試圖消除''produces'',我試圖返回一個字符串,如「OK」和我仍然得到相同的錯誤。 @cralfaro – gon250
@ gon250你能否用你正在測試的數據更新你的問題?和錯誤消息?只是爲了與您同時更新 – cralfaro
我已經添加了新的代碼。基本上我已經刪除了產品,並確保我返回一個字符串。 – gon250