Redirect after POST request with jquery

后端 未结 3 981
日久生厌
日久生厌 2021-02-01 11:27

I\'m working with Django. I have an HTML page, where I do some Javascript stuff, and then I do a jQuery post, in this way:

$.ajax({ 
  url: \'/xenopatients/meas         


        
3条回答
  •  逝去的感伤
    2021-02-01 11:45

    On button click call this function() below and pass the parameter, in my case I passed new

    function checkforNew(){
                    //jQuery.post('<%=request.getContextPath()%>/InspectionController?&oper=new');
    
                    jQuery.ajax({
                        type: "POST",
                        url: '<%=request.getContextPath()%>/MyController?&oper=new',
                        //data: {'obj':data},
                        dataType: "json",
                        success: function(response){
                            window.location.href = response.redirect;
                        }
                    });
                }
    

    Inside your servlet you need to mention following code, for the page to redirect.

    String destination = "/mypage.jsp;
    
                    response.setContentType("application/json");
                    JSONObject responsedata = new JSONObject();
                    responsedata.put("redirect", destination);
    
                    out.print(responsedata);
                    out.flush();
    

提交回复
热议问题