Screenshot showing an ERROR I am attempting to input a value using an AJAX call through a Spring MVC controller. However, it is throwing an Object Error when the button is clicked. Can someone please assist me with this issue?
CODE: Ajax Code:
<script type="text/javascript">
// $(document).ready(function() {
function doAjaxPost() {
// // get the form values
$.ajax({
type : "POST",
async: "false",
// url : "${pageContext.request.contextPath}/leadstatus_creation",
url :'/ajax/leadstatus_creation',
data: $('#frm-createlead-status').serialize(),
success : function(data) {
if(data != null && data !='')
{
$('#txtleadname').val(data);
}
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
}
// });
</script>
LeadController.java
/**
* Method used for View lead status get method.
* @param map
* @return
* @throws Exception
*/
@RequestMapping(value="/ajax/leadstatus_creation",method=RequestMethod.POST)
public @ResponseBody String createleadstatus(BindingResult result,HttpSession session,HttpServletRequest request,HttpServletResponse response) throws Exception{
String resultStr=leadDao.createLeadStatus(null);
try
{
if(session !=null)
{
String leadstatus = request.getParameter("txtleadname");
Map<Integer,Object>obj=null;
obj=new HashMap<Integer , Object>();
obj.put(1, leadstatus);
obj.put(2, 1);
if(leadDao.createLeadStatus(obj) != null)
{
resultStr = "true";
}
else
{
resultStr = "false";
}
resultStr = JSONValue.toJSONString(resultStr);
}
response.setContentType("application/json");
response.getWriter().write(resultStr.toString());
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
return resultStr;
}
}
Form Code: