This time I will show you how to use js to obtain ModelAndView. What are theprecautionsfor js to obtain ModelAndView. The following is a practical case, let's take a look.
1 Method 1 [Valid]
Yes, the access method is the same as elexpression.
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; }
Use this userId as a query condition in the js in the page jsp file:
2 Method 2
【Effective? 】
Is the platform returning js or json? This must be clarified!
Assume that thestringreturned by the background is stored in responseText, then
If it is js, then
var result = eval("(" + responseText + ")");
If it is json, then
var result = JSON.parse(responseText);
3 Method Three [Effective]
Add hidden fields,
Easy for js to read
var passflag=document.getElementById("autoflag");
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
How to convert the html fields in the data into HTML tags
Detailed explanation of the steps to implement request interception with vue axios
The above is the detailed content of How to use js after getting ModelAndView. For more information, please follow other related articles on the PHP Chinese website!