Ajax调用:Ajax调用总是用SpringMVC返回错误
$.ajax({
type:'post',
url:'https://hybris.local:9002/store/verify?productCodePost='+productid,
data : {notifyemail : notifyemail},
dataType : "text",
success : successmethod,
error : function(data, status) {
//alert("Error "+status);
$('#showbecomepartnerMessage').show();
}
});
alert("test values are"+notifyemail);
document.getElementById('notifyemail').value='';
}
function successmethod(data) {
if (data != null) {
alert('Success');
$('#showemailMessage').show();
} else {
alert('Error');
}
}
控制器:
@RequestMapping(value = "/verify", method = RequestMethod.POST, produces = "application/json")
public String verifyEmail(@RequestParam("productCodePost") final String code, final Model model,
@Valid final AddToCartForm form)
{
System.out.println("Inside Verify method");
final String email = form.getNotifyemail();
System.out.println("Email is " + email);
System.out.println("Product code is== " + code);
final Boolean status = true;
if (email != null)
{
System.out.println("Email id is" + email);
notifyStockEmail(email, code);
}
if (status.booleanValue())
{
System.out.println("value of Boolean " + status.booleanValue());
//return "success";
model.addAttribute("success", "success");
}
else
{
//return "fail";
model.addAttribute("error", "error");
}
return "success";
}
在上面的代码中,我正在做一个Ajax调用并调用控制器“/验证”,并从控制器我返回一个布尔值为true,但每次在jsp中执行错误方法而不是成功method.So如何通过传递来自控制器的真实值如上调用成功方法。任何帮助将不胜感激。
什么正在由服务器返回的错误? – David
你是否使用spring安全保护应用程序? –
@David内部控制台重新调用的值为true ..但在ajax函数中调用错误方法... – User2413