Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to retrieve the value sent by a controller.I am unable to find the mistake.
C#
$(document).ready(function(){
    $("#name").val("welcome");
        $("button").click(function(){
        var n = $("#name").val();
        $.ajax({
                type:"post",
                url:"${pageContext.request.contextPath}/direct",
                data:{name : n},
                success:function(data){
                //displayfromcontroller();
                 $(".display_area").html(data); 
                alert("coming value = "  + data);       
            },
            error:function()
            {
                alert("Error ");
            }   
            });
         });
    })

This is my controller. I have tried returning name of a view, tried returning map.
C#
@RequestMapping(value = "/direct", method = RequestMethod.POST)
    public String direct(HttpServletRequest request,HttpServletResponse 
response) {
         String fullname=request.getParameter("name");
        System.out.println("hehjgeuqg;qg;     "+fullname);
        /*model.addAttribute("name", fullname);*/
        Map<String, String> loPageFields = new HashMap<String, String>();
        loPageFields.put("status", fullname);
        String fname=loPageFields.get("status");
        System.out.println(fname);
        return loPageFields.get("status");
        //return fname;
    }


What I have tried:

I have tried returning a view, map and a string from the controller.
Whenever I return a view whole code of that particular view is being displayed in the display_area div tag. Whenever i tried returning String it enters success block but just displays the alert as "coming value= ".
Posted
Updated 13-Sep-17 21:03pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900