자동 완성 jQuery 플러그인 및 ASP.NET C#
-
06-07-2019 - |
문제
JQuery AutoComplete 플러그인을 사용하고 있으며 AutoComplete를 위해 다양한 문자열을 전달하고 있습니다 (아래 코드 참조). 내 데이터를 얻기 위해 호출하는 방법 (GetCustomerNames)은 문자열 배열을 반환하는 것입니다. getCustomerNames 메소드로 매개 변수를 전달할 수있는 방법을 찾아야합니다. 누구든지 이것을 도울 수 있습니까?
다음은 default.aspx 페이지의 마크 업 코드입니다.
<head runat="server">
<title></title>
<script type="text/javascript" src="js/jquery-1.3.2.js" ></script>
<script type="text/javascript" src="js/jquery.autocomplete.js" ></script>
<script type="text/javascript">
//Working, but uses results output to an aspx page using StringBuilder, trying
//to find a way to get the data with json
//$(document).ready(function() {
// $("#example").autocomplete('AutoCompleteData.aspx');
//});
$(document).ready(function() {
$("#example").keyup(function() {
$.ajax({
type: "POST",
url: "Default.aspx/GetCustomerNames",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$("#example").autocomplete(msg.d);
},
error: function(msg) {
alert("error");
}
});
});
});
</script>
고객 이름:
다음은 GetCustomerNames 메소드를 구현하는 페이지 뒤에있는 Default.aspx.cs 코드의 코드입니다.
[WebMethod]
public static string[] GetCustomerNames()
{
string[] data = new string[] {"Andrew", "Ramona", "Russ", "Russell", "Raymond"};
return data;
}
해결책
당신은 사용할 수 있습니다 data
해시 매개 변수를 메소드로 전달합니다.
$.ajax({
type: 'POST',
url: 'Default.aspx/GetCustomerNames',
data: '{ parameterName: "some test value" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(msg) {
$("#example").autocomplete(msg.d);
},
error: function(msg) {
alert("error");
}
});
웹 방법은 다음과 같습니다.
public static string[] GetCustomerNames(string parameterName)
제휴하지 않습니다 StackOverflow