[英]JSON object not retrieved on server
我通過在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”,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.