这是我的网络方法:
[WebMethod]
public string getitemamount(string item_name)
{
DataTable dt = da.executequery("select unit_price from item_details where item_name='" + item_name.ToString() + "'");
string a = dt.Rows[0]["unit_price"].ToString();
return a;
}
这是我的ajax:
<script language="javascript" type="text/javascript">
$(function() {
$("#" + '<%=ddl_item.ClientID %>').change(function() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebService2.asmx/getitemamount",
data: "{'item name':'" + $("#" + '<%=ddl_item.ClientID %> option:selected').val() + "'}",
dataType: "json",
success: function(msg) {
var data = eval("(" + msg.d + ")");
alert(msg.d);
$("#" + '<%=txt_unitprice.ClientID %>').empty();
for (var i = 0; i < msg.d.length; i++) {
var unit = data[i].unitprice;
$("#" + '<%=txt_unitprice.ClientID %>').val(unit);
$("#" + '<%=txt_unitprice.ClientID %>').val($("#" + '<%=txt_unitprice.ClientID %>').val());
}
},
error: function(re) { alert(re.toString() + " FROM ERROR"); }
});
});
});
</script>
当我运行web服务时它工作..当我使用ajax调用webmethod时它返回的对象对象错误....感谢提前pl帮帮我