jQuery Ajax POST request not hitting Spring controller -
i unable hit spring controller using jquery ajax post. trying fetch list of string using json response.
my javascript function called when dropdown selected:
function doajaxpost() { var name = $('#selected_report').val(); alert("post ajax request initiating.... name : " + name); $.ajax({ type: "post", url: "/newilr/interfacereportssearch/findentitytypes", contenttype: "application/json", data: json.stringify({selectedreport:name}), datatype: "text", success: function(response){ if(response.status == "success"){ alert("success"); }else{ alert("failure"); } }, error: function(e){ alert('error: ' + e); } }); }
note 2 of above alerts displayed (post ajax request initiating... , 'error: ' + e))
spring controller handle ajax request:
@requestmapping (value="/interfacereportssearch/findentitytypes",method=requestmethod.post, produces = "application/json") public @responsebody jsonresponse adduser(@requestbody string selectedreport , bindingresult result ){ system.out.println("ajax request received! reportname = " + selectedreport);
note above print statement never executed. not see single console output, maybe request not server.
no special beans added servlet condiguration have below 2 added:
<mvc:annotation-driven /> <context:annotation-config/>
following jars added classpath.
jackson-core-2.2.0 jackson-annotations-2.2.0 jackson-databind-2.2.0
update
solved: changed datatype json
change url attribute of ajax request following:
url: "${pagecontext.request.contextpath}/newilr/interfacereportssearch/findentitytypes",
this should job you.
Comments
Post a Comment