Joh*_*lla 4 javascript jquery playframework playframework-2.0
我有一个关于向播放控制器发送json数据的问题.
seach.scala.html
$.ajax({
type : "POST",
dataType: 'json',
data: {
'filter': "John Portella"
},
url : "@routes.Search.findPag()",
success: function(data){
console.log(data);
}
});
return false;
Run Code Online (Sandbox Code Playgroud)
控制器: POST /find/findPag Search.findPag()
public static Result findPag(){
JsonNode json = request().body().asJson();
return ok();
}
Run Code Online (Sandbox Code Playgroud)
调试我得到json = null.你认为哪个可能是问题?谢谢.
你必须对数据进行字符串化.就像现在一样,我认为.toString()将在数据对象上调用,而不是可以在服务器端正确解析为JSON的东西.
var d = { 'filter': "John Portella" };
$.ajax({
type : "POST",
dataType: 'json',
data: JSON.stringify(d),
url : "@routes.Search.findPag()",
success: function(data){
console.log(data);
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8945 次 |
| 最近记录: |