我的目标是通过调用选择框值的我strus2动作变化来显示由负荷消费ID的客户信息。如何在jQuery函数从动作类返回JSON结果
我的问题是:我应该从我的动作类返回得到JSON格式
我尝试下面的代码的价值,但我不知道什么是错的
<script type="text/javascript">
$(function()
{ alert("This function is calling, on change event of selectbox and customer id="+$(this).val());
$("#customersjsonlstid").change(function(e)
{
$.ajax({
url: 'showCustomerInfoById.action', //action name
data: "customerid=" + $(this).val(),
dataType: "json",
success: function(data) {
// Set the inputs from the json object , json output : {"price": "123.40", "distributor": "XYZ Inc."}
$('#autocompleter_div_result1').val(data.distributor); //showing data on particular div
$('#autocompleter_div_result2').val(data.price); //showing data on particular div
}
});
});
});
</script>
选择框:
<sj:select
id="customersjsonlstid"
name="editionType"
href="%{customerJsonselecturl}"
list="lstcust"
listValue="name"
listKey="id"
autocomplete="false"
/>
<div id="autocompleter_div_result">`
struts.xml的
<action name="showCustomerInfoById" class="v.esoft.actions.customerdetails.CustomerSelectAction" method="CustomerdetailsById">
<result name="success" type="json"/>
</action>
Action类
public class CustomerSelectAction extends ActionSupport {
private String customerid;
//---------------------------------------------------------
public String CustomerdetailsById()
{
System.out.print("--------Method called, customer id-----------"+customerid);
return customerid;
}
//---------------------------------------------------------
public String getCustomerid() {
return customerid;
}
public void setCustomerid(String customerid) {
this.customerid = customerid;
}
}
你会得到什么错误? – mohkhan
@mohkhan问题在这里'url:'showCustomerInfoById.action''我删除了.action函数正在调用。 –
@mohkhan我更新了我的问题,请再阅读一次。 –