嗨我正在使用
spring mvc ajax.我通过传递用户ID进行了ajax调用.一切顺利成功返回到ajax但是当我提醒响应时,它简单地显示了html页面代码.请帮我解决这个问题.
我想我没有很好地编码我的ajax.请以正确的方式帮助我
控制器代码:
public @ResponseBody ModelAndView abc(HttpServletRequest httpServletRequest,
HttpSession session, ModelMap map){
ModelAndView modelAndView = new ModelAndView("abcd.page",
"commandName", object);
return modelAndView;
Ajax代码:
$(".userDetails").click(function() {
alert("clicked");
var userId=$(this).parent().parent(). parent().find(".userId").
text().trim();
alert("userId :"+userId);
$.ajax({
url : 'ABC.htm',
type : 'GET',
data: {userId:userId},
beforeSend: function(xhr) {
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
},
success : function(response) {
alert("success");
alert(response);
},
error : function(res) {
alert("error");
},
});
return false;
});
警报的输出(响应);是
编辑:任何人都可以告诉为什么ajax给成功的HTML内容…经过多次变化后,我得到了相同的警报.
再次编辑:我认为我在控制器中没有任何问题.请建议我正确编码我的ajax的解决方案.这里好像错了.如何在ajax中获取ModelAndView对象