This is the method
[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;
}
}
}
I am calling it like this…
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);
}
});
I’ve tried various combinations, without contentType and datatype, with get instead of post, but still nothings seems to work so far. Can anyone help?
You must have to remove
~operator and I think there is something wrong with Webservice code and json parameter.Have a look at sample (both .aspx and .asmx are under the root of webapp):
sample.aspx
SampleWs.cs