springMVC中jquery ajax的传值及使用的有关问题
求助springMVC中jquery ajax的传值及使用的问题
前台部分代码:
function show(type)
{
$.ajax({
type: "POST",//使用post方法访问后台
dataType: "json",//返回json格式的数据
url: "/notice-list.json",//要访问的后台地址
data:
{
"type" : type //要发送的数据
},
// complete :function(){$("#load").hide();},//AJAX请求完成时隐藏loading提示
error: erryFunction,
success: loadNoticePart //msg为返回的数据,在这里做数据绑定
})
}
后台部分代码:
@ResponseBody
@RequestMapping(value = Url.NOTICE_LIST_DEFAULT, method = RequestMethod.GET)
public void getNewsTitle(ModelMap model, HttpServletRequest request,
HttpServletResponse response, String type)
{
String type1 = request.getParameter("type");
Map<String, Object> result = new HashMap<String, Object>();
List<String> titlesList = systemNoticeService.queryNoticeTitles(type);
result.put("success", "success");
result.put("titleList", titlesList);
String json = JSONArray.toJSONString(result, true);
try
{
response.getWriter().print(json);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
现在能进后台 但是type 和 type1的值都是null! 我是第一次用这个框架,想问下是要配置什么么? 另外 我手动给type赋值之后,跑完代码,json的值直接打印在了页面上,没有进入回调函数? 什么情况呀?
------解决思路----------------------
参数 写在注解里 如 @RequestMapping
前台部分代码:
function show(type)
{
$.ajax({
type: "POST",//使用post方法访问后台
dataType: "json",//返回json格式的数据
url: "/notice-list.json",//要访问的后台地址
data:
{
"type" : type //要发送的数据
},
// complete :function(){$("#load").hide();},//AJAX请求完成时隐藏loading提示
error: erryFunction,
success: loadNoticePart //msg为返回的数据,在这里做数据绑定
})
}
后台部分代码:
@ResponseBody
@RequestMapping(value = Url.NOTICE_LIST_DEFAULT, method = RequestMethod.GET)
public void getNewsTitle(ModelMap model, HttpServletRequest request,
HttpServletResponse response, String type)
{
String type1 = request.getParameter("type");
Map<String, Object> result = new HashMap<String, Object>();
List<String> titlesList = systemNoticeService.queryNoticeTitles(type);
result.put("success", "success");
result.put("titleList", titlesList);
String json = JSONArray.toJSONString(result, true);
try
{
response.getWriter().print(json);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
现在能进后台 但是type 和 type1的值都是null! 我是第一次用这个框架,想问下是要配置什么么? 另外 我手动给type赋值之后,跑完代码,json的值直接打印在了页面上,没有进入回调函数? 什么情况呀?
------解决思路----------------------
参数 写在注解里 如 @RequestMapping