public class searchResult
{
public int id;
public string name;
}
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
[System.Web.Script.Services.GenerateScriptType(typeof(searchResult))]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public searchResult[] Search(int txtSearch)
{
//Semuler to slow internet connection
System.Threading.Thread.Sleep(2000);
//Declare collection of searchResult
List<searchResult> resultList = new List<searchResult>();
DataSet ds = Classes.getEmployeeDetailSet("SELECT [Employee ID],[First Name] FROM [Employee$] WHERE [Employee ID] like '" + txtSearch + "%'");
DataTable dt = new DataTable();
dt = ds.Tables[0];
if (dt.Rows.Count > 0)
{
searchResult result = new searchResult();
result.id = int.Parse(dt.Rows[0]["Employee ID"].ToString());
result.name = dt.Rows[0]["First Name"].ToString();
resultList.Add(result);
}
return resultList.ToArray();
}
私は次のようなリストを作成しました
List<searchResult> resultList = new List<searchResult>(); this
and i have return that list
to call this i have use ajax code like this
$.ajax({ type: "POST",
url: "WebService1.asmx/Search", //function that in web service
data: "{txtSearch:" + $("#txtSearch").val() + "}", // passing value of txtSearch input
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
var result = response.d;
var value = '';
$.each(result, function(index, res) {
value = value + res.id + res.name;
});
alert(value);
alert("Record was updated successfully,,");
},
error: function(msg) {
alert("Error while calling web service,,");
}
});
私の問題は、データベースから要素を 1 つしか取得していないことです
ここのajax応答でリストを分離できないと思います
$.each(result, function(index, res) {
value = value + res.id + res.name;
});
この id+name を使用して配列を作成したい
助けてください