Return to the previous page. For AJAX requests on the page, the solution to the Get request is invalid. Return to the previous page ajax
The cause of the problem has recently encountered a common situation in a project. The requirement is as follows: when a user enters the "my personal center, you can click the button to jump to the certification materials filling page. After clicking this button, you will be redirected to the certification materials filling page, fill in the materials, and submit the materials successfully. When the user directly returns to the previous page. You must change the authentication status to "authentication in progress ". In this case, you need to use an AJAX method to query the authentication status and modify the status display of the page. At that time, the ajax method was not written according to the standard method. The default method is Get request. The front-end JS Code is as follows:
Window. onload = function () {var isProfesser = $ ('# isProfesser '). val (); var isreview =$ ('# isreview '). val (); var userid = $ ('# myid '). val (); if (isProfesser = '0' & isreview = '0') {$. ajax ({url: "/isAuthenticing", data: {userid: userid}, success: function (data, textStatus, jqXHR) {if (data. result = '1') {$ ('# approveadd a'0000.html ("+ authentication in progress") }}, error: function (){}});} // getMyQusetionInfo ();}
The backend controller receives GET by default.
@ RequestMapping (value = "/isAuthenticing", method = RequestMethod. GET) @ ResponseBodypublic Map <String, Object> isAuthenticing (@ RequestParam ("userid") String userid, HttpServletRequest request) throws IOException {// method body ;}
Solution practices prove that the Get method is not feasible. Every time you move back to the previous page, the ajax method on the page will be executed as usual, but it will not request the controller in the background, the value returned by the request is also the value of the last page load. I am not clear about the specific reason. Later, with a try, I used the POST request. unexpectedly, the POST request was used, and the process went through. The front-end JS Code is as follows:
Window. onload = function () {var isProfesser = $ ('# isProfesser '). val (); var isreview =$ ('# isreview '). val (); var userid = $ ('# myid '). val (); if (isProfesser = '0' & isreview = '0') {$. ajax ({url: "/isAuthenticing", data: {userid: userid}, type: 'post', success: function (data, textStatus, jqXHR) {if (data. result = '1') {$ ('# approveadd a'0000.html ("+ authentication in progress") }}, error: function (){}});} // getMyQusetionInfo ();}
Background code:
@ RequestMapping (value = "/isAuthenticing", method = RequestMethod. POST) @ ResponseBodypublic Map <String, Object> isAuthenticing (@ RequestParam ("userid") String userid, HttpServletRequest request) throws IOException {// method body}
Hope to help those who encounter the same problems as me. Note: The red part indicates the modified part.
If you want to learn more about the technical articles, follow the blog of Bai yixiu CAI.
Personal Website: http://penglei.top/
Github: https://github.com/whitescholars
Weibo: http://weibo.com/u/3034107691? Refer_flag = 1001030102 _ & is_all = 1