这是方法
[WebMethod]
public static string[] GetCustCodeFromCustomerName(string[] custName)
{
if (custName.Length == 0)
return null;
else
{
List<string> items = new List<string>();
StringBuilder custList = new StringBuilder();
string custListstr = string.Empty;
for (int i = 0; i < custName.Length; i++)
custList.Append(custName.ElementAt(i) + ", ");
custListstr = custList.ToString().Substring(0, custList.Length - 2);
try
{
SqlCommand cmd = new SqlCommand();
SqlDataReader sdr;
DataSet ds;
cmd.CommandText = "sp_sel_custcodeFromCustName";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@customercodeinlist", custListstr);
cmd.Parameters.AddWithValue("@BranchId", Globals.BranchID);
cmd.Parameters.AddWithValue("@Flag", 1);
sdr = AppClass.ExecuteReader(cmd);
ds = AppClass.GetData(cmd);
while (sdr.Read())
{
items.Add("" + sdr.GetValue(0));
}
sdr.Close();
sdr.Dispose();
return items.ToArray();
}
catch (Exception)
{
return null;
}
}
}
我这样称呼它...
custList = $(':checkbox:checked').map(function () { return $(this).closest('tr').find('.grdCustName').text() }).get();
$.ajax({
type: "post",
url: "~/AutoComplete.asmx/GetCustCodeFromCustomerName",
data: "{custName:'" + custList + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
},
success: function (result) {
alert("success" + result);
}
});
我尝试了各种组合,没有contentType
and datatype
,withget
而不是 post,但到目前为止似乎仍然没有任何效果。任何人都可以帮忙吗?