まず、このテーマについて多くの調査を行いましたが、答えや完全な例を見つけることができませんでした。私はjqueryの経験があまりないので、私が達成しようとしていることの簡単なサンプルを探しています.
グリッド、コンボボックス、オートコンプリートなどを設定するために使用できる json を返す Web サービス (asmx) が必要です。Visual Studio 2008 を使用しています。
ASMX :
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class Services : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<Preceptor> SearchPrecetor()
{
List<Preceptor> myPreceptorList = new List<Preceptor>();
for (int i = 0; i < 10; i++)
{
Preceptor myPreceptor = new Preceptor();
myPreceptor.Id = i;
myPreceptor.Name = "Name" + i.ToString();
myPreceptorList.Add(myPreceptor);
}
return myPreceptorList;
}
public class Preceptor {
public int Id {get; set; }
public string Name { get; set; }
}
}
Javascript :
$(document).ready(function() {
$("#acPreceptors").kendoAutoComplete({
minLength: 3,
dataTextField: "Name",
dataSource: {
type: "json",
serverFiltering: true,
serverPaging: true,
pageSize: 20,
transport: {
contentType: "application/json; charset=utf-8",
type: "POST",
read: "../Services/Services.asmx/SearchPrecetor"
}
}
});
});
これは私が得ているエラーです:
Uncaught TypeError: Object #<Document> has no method 'slice'
私の推測では、プロセス全体にまだ何か問題があり、json がクライアントに正しく到達していません。繰り返しますが、私はjqueryの経験があまりありません。これを行う方法の簡単で完全な例を本当に感謝しています.
考え、リンク、コード、修正をいただければ幸いです。ありがとう