我在頁面上有一個表單,而後我在表單中填了數據後經過ajax把參數發送給後臺action,個人ajax是這樣寫的: $("#sub").click(function() { //獲取表單中id爲pname和count的文本值付給property的兩個屬性 var property={"name":$("#pname").val().trim(), "count":$("#count").val().trim()}; //構造place對象 var place={"name":$("#place").val().trim()}; //post和後臺交互 $.post( "SendPropertyInfoAjax.action", {"property":property, "place":place } ); }); 後臺action的代碼以下: public class Test extends ActionSupport{ private Property property; private Place place; public Property getProperty() { return property; } public void setProperty(Property property) { this.property = property; } public Place getPlace() { return place; } public void setPlace(Place place) { this.place = place; } public void updatePropertyInfoAjax() throws Exception { System.out.println("count is: "+property.getCount()); System.out.println("propertyname is: "+property.getName()); System.out.println("placename is: "+place.getName()); } } 我這樣作是不對的,由於post提交過來的值在action中就沒接收到,我若是要想得到post請求傳遞過來的property和place對象,action中應該要怎麼寫啊?
分享到:ajax
2013-11-28 09:10提問者採納post
你ajax傳遞的是這樣傳:
$.post(
"SendPropertyInfoAjax.action"
,
{
"property.name"
:$(
"#pname"
).val().trim(),
"property.count"
:$(
"#count"
).val().trim(),
"place.name"
:
":$("
#place").val().trim()
}
);