例如用ajax来修改数据,只要发修改请求给springmvc,而不需要他返回的数据。那么
springmvc不返回数据给ajax包括空字符串可以吗。
``` function phbutton(){
var phone=prompt("请输入新的手机号码!");
if(valid(phone)==false){
alert("手机号码格式错误!");
return;
}
$.ajax({
type:"post",
url:"./newphone",
data:phone,
contentType:"application/json;charset=UTF-8",
success: function(data){
alert("手机号码更改成功!");
var e=document.getElementById("phone");
e.innerHTML=data;
},
error:function(XMLHttpRequest, textStatus, errorThrown){
alert(xhr.responseText+" "+textStatus+" "+errorThrown);
}
});
@RequestMapping(value="/newphone",method =RequestMethod.POST)
public void newphone(@RequestBody String phone){
System.out.println(phone);
}
我试了一下,ajax请求的时候会这样报错:Request method 'POST' not supported
但是如果Controller writer()返回点什么的话那么就不或报错。
还有就是直接在参数列表中添加PrintWriter writer,然后没有使用writer的话,也不会报错。难道如果不操作writer他会自己返回空字符吗?