【发布时间】:2015-09-30 19:01:38
【问题描述】:
对于我的应用程序,我正在编写一个 POST 请求以从复选框列表中发送参数数组。它适用于获取请求,但不适用于发布请求。我的代码有什么错误。
我在客户端的代码用于向服务器发送 ajax 请求。
$(".add").click(function(){
monitoring.length=0;
nonMonitoring.length=0;
$('.modal-body input:checked').each(function() {
monitoring.push($(this).val());
});
$('.addkeywords input:checked').each(function() {
nonMonitoring.push($(this).val());
});
// alert(monitoring[2]+ " " + nonMonitoring[2]);
var monitoringLength=monitoring.length;
var nonMonitoringLength=nonMonitoring.length;
$.ajax({
type : "POST",
url : '/rest/channelstats/my/rest/controller',
data : {
// monitoring : monitoring,
// nonMonitoring: nonMonitoring,
monitoringLength: monitoringLength,
nonMonitoringLength: nonMonitoringLength,
},
success : function(data) {
// var keywordsList=data
//console.log(keywordsList);
// htm = "" ;
}
});
})
我在服务器端的 java 代码。
@RequestMapping(value="/rest/channelstats/my/rest/controller",method = RequestMethod.POST)
public void monitorKeywords(@RequestParam(value="monitoringLength",required=true)int monitoringLength,@RequestParam(value="nonMonitoringLength",required=true)int nonMonitoringLength){
System.out.println("MonitoringLength =>" +monitoringLength);
System.out.println("NonMonitoringLength=>" +nonMonitoringLength);
}
}
它适用于 HTTP GET 请求,但不适用于 POST 请求。我应该如何解决这个问题?
【问题讨论】:
-
您遇到的错误是什么?
-
它没有显示任何错误它没有在控制台中打印输出
-
在我的 java 控制台中.. 我的意思是在我的 Eclipse 控制台中
-
嗨,你解决过这个问题吗?我也遇到过这个问题。
标签: java jquery ajax spring model-view-controller