Below I will share with you a brief discussion on the problem of obtaining the ModelAndView value with js. It has a good reference value and I hope it will be helpful to everyone.
Can't the return value of ModelAndView be received in JS? Does it have to be received in a JSP page?
1 Method 1 [valid]
#Yes, it is the same as the el expression access method .
Sample code, a userId is stored in the Action of a data display request:
@RequestMapping(value="/diary") public ModelAndView toDiaryList(HttpSession session){ ModelAndView view = new ModelAndView("/diary_list"); TbUser user = (TbUser)session.getAttribute(SystemConstant.CURRENT_USER); //set info of current user if(user!=null){ Integer id = user.getId(); view.addObject("userId",id); } return view; }
in the js in the page jsp file Use this userId as the query condition:
##2 Method 2
【efficient? 】 Is the platform returning js or json? This must be clarified! Assume that the string returned by the background is stored in responseText, then If it is js, thenvar result = eval("(" + responseText + ")");
var result = JSON.parse(responseText);
3 Method three [valid]
Add hidden fields,var passflag=document.getElementById("autoflag");
Ajax core XMLHttpRequest summary
Solving the problem of ajax cross-domain request data cookie loss
Use ajax to change page content and address bar URL without refreshing
##
The above is the detailed content of A brief discussion on the problem of obtaining ModelAndView value in js. For more information, please follow other related articles on the PHP Chinese website!