后台用servlet拼接出json字符串,前台用ajax接收,datatype设为text/html能顺利取到字符串,但是datatype改为json后ajax响应错误
String json="{";
json+="'userName':'tiny',";
json+="'userNo':'123'}";
writer.write(json);
后将输出字符串改为
String json="{";
json+="\"userName\":\"tiny\",";
json+="\"userNo\":\"123\"}";
writer.write(json);
则成功