我通过在ajax中将其字符串化来传递JSON对象。但是不会在服务器端检索到它。
jsonData = {
"10001":{
"2":["33","","8","","9",""],
"name":"abc",
"token":"10001",
"01":["","36","","1","1","8"]
},
"10002":{
"2":["67","87","78","5","44",""],
"name":"dfds",
"token":"10002",
"01":["9","","7","3","5","7"]
}
}
使用ajax传递对象,如下所示:
var jsonData = JSON.stringify(emp);
$.ajax({
url: "SaveController",
type: "POST",
dataType: "json",
data: {empData:jsonData},
contentType: "application/json; charset=utf-8",
async: false,
cache: false,
success: function(response){
alert("Data Saved...");
alert(JSON.stringify(response));
},
error: function(err){
alert("Error in Saving Data...");
alert(JSON.stringify(err));
}
});
然后在我的SaveController中检索它,如下
response.setContentType("application/json");
PrintWriter out = response.getWriter();
try {
String term = request.getParameter("empData");
System.out.println( term);
} finally {
out.close();
}
在客户端上检查了neturl的数据后,将其作为参数字符串发送,但在服务器端未使用getParameter进行检索。它返回null。
在阅读了许多文章之后,使之起作用的调整是通过删除
contentType:“ application / json; charset = utf-8”,
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句