无法访问 Action 类中的 AJAX 输入参数
JSP/JQuery 调用:-
$.ajax({
url: "ApplyCouponCode",
type: "POST",
data: {couponCode: $('#PaymentMethod_couponCode').val()},
dataType: "json",
error: function(){
alert('Error');
},
success: function(data){
alert('SUCCESS');
$('#spanValidatedCoupon').text('Is coupon valid? ' + data.couponIsValid + ' couponAmount = ' + data.couponAmount);
}
});
Action 类:
public String applyCouponCode() throws Exception {
if(logger.isDebugEnabled()){
logger.debug("data: couponCode '" + couponCode + "'");
}
return SUCCESS;
}
调用 Action 类方法 [applyCouponCode]。但优惠券代码为空..请告知。 couponCode 有公共 getter/setter 方法..我还需要做什么?
JSP/JQuery call:-
$.ajax({
url: "ApplyCouponCode",
type: "POST",
data: {couponCode: $('#PaymentMethod_couponCode').val()},
dataType: "json",
error: function(){
alert('Error');
},
success: function(data){
alert('SUCCESS');
$('#spanValidatedCoupon').text('Is coupon valid? ' + data.couponIsValid + ' couponAmount = ' + data.couponAmount);
}
});
Action Class:
public String applyCouponCode() throws Exception {
if(logger.isDebugEnabled()){
logger.debug("data: couponCode '" + couponCode + "'");
}
return SUCCESS;
}
The Action class method [applyCouponCode] is invoked. But couponCode is null.. please advise. couponCode has public getter/setter methods .. what else do i need to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您直接前往 ApplyCouponCode?couponCode=your_coupon_code 会发生什么
What happens if you go directly at ApplyCouponCode?couponCode=your_coupon_code
我认为你的操作方法应该以 couponCode 作为参数。假设 couponCode 是字符串类型,您的操作方法应如下所示:
希望这会有所帮助。
I think your action method should take couponCode as a parameter. Assuming couponCode is type string, your action method should look something like this:
Hope this helps.