The ajax request is successful, json is returned in the background, and the front-end page does not execute success

The title ajax request is successful, json is returned in the background, and the front-end page does not execute success

I found various reasons on the Internet, and there is another possibility, using postman to return data normally. It has been intercepted and requires a cross-domain request.
Need to add this cross-domain request response.setHeader("Access-Control-Allow-Origin","*");

@GetMapping("/query")
    public Page<Admin> findByPage(Integer page, HttpServletResponse response){
    
    
        response.setHeader("Access-Control-Allow-Origin","*");
        if(page==null||page<=0){
    
    
            page=0;
        }else {
    
    
            page -=1;
        }
        return adminService.findAllByPage(page,5);
    }

Don't forget the response of findByPage(Integer page, HttpServletResponse response).
Finally found the remaining reason,
you may also need to add one before response.setHeader("Access-Control-Allow-Origin","*");

response.setHeader("Cache-Control","no-cache");

Don’t forget, if you submit the form, the action must be removed. The type of the button is button. If you don’t write it, it may default to submit. You must write the attributes correctly (the button tag does not indicate the type and it’s been a long time. Find the answer to the question).

The json backend returns String, and the ajax receiving either sets the jsontype to text or not.

Guess you like

Origin blog.csdn.net/qq_39088110/article/details/107824708
Recommended