I am trying to perform this AJAX post but getting a server 500 error. If I don't send any data i can see it hits break point set in the controller. But when I send data it doesnt and returns 500 error. help? Thanks.
In firebug console,
The request header hasContent-Type application/x-www-form-urlencoded; charset=UTF-8
and Response as com.hearsay.example.mktpx.ui.action.LoadDefaultsAction.retrieveBenchmark()
Code :
$.ajax( {
type : "POST",
url : "loadBenchMark",
data : {'ruleset':'1'},
success : function(data) {
console.log("success");
},
error:error : function(request, textStatus, errorThrown) {
console.log("Error Throw开发者_StackOverflow中文版n:" +request.statusText);
}
});
Action Class:
public String retrieveBenchmark(int ruleset) {
setBenchmarkProductList(retrieveBenchmarkProductList());
return SUCCESS;
}
Struts.xml
<action name="loadBenchMark"
class="com.hearsay.example.mktpx.ui.action.LoadDefaultsAction" method="retrieveBenchmark">
<result type="json"></result>
</action>
First, remove the ruleset
parameter from the method. Then, add an instance variable instead in the action class, with standard getter and setter methods - like this:
private int ruleset // or String, if you're passing String values
public int getRuleset() {
return this.ruleset;
}
public void setRuleset(int ruleset) {
this.ruleset = ruleset;
}
This is the way parameters are passed to a Struts action - Struts will call the appropriate setter. Remember to use correct data types - do not pass String
values for int
variables etc.
精彩评论