jQuery 通过 JSON 自动完成来自 ASMX 的名称/值对
我有两个文本框,我试图将其用于自动完成。两者的源数据均来自 ASP.NET ASMX Web 服务,以 JSON 格式返回。我正在返回一个列表,其中 NameValue 定义为:
public struct NameValue { public string Name;公共字符串值; }
我如何解析此数据,以便可以将所选下拉列表名称的值存储在隐藏字段中?
这是页面加载时到目前为止我的代码,并且 msg.d
包含 JSON 数据(我看到 msg.d[0].Name
和 msg. d[0].值
)
$.ajax({
type: "POST",
url: '/Services/Team.asmx/GetClubTeams',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$('#<%= txtFromTeam2.ClientID %>, #<%= txtToTeam2.ClientID %>').autocomplete({
source:msg.d
});
},
error: function(xhr, msg) {
alert(msg);
}
});
I have two textboxes which I am trying to use for autocomplete. The source data for both is coming from an ASP.NET ASMX web service, returned in JSON format. I'm getting back a List where NameValue is defined as:
public struct NameValue { public string Name; public string Value; }
How can I parse this data such that the selected dropdown Name's Value can be stored away in a hidden field?
Here is my code thus far when the page loads, and msg.d
contains the JSON data (I see msg.d[0].Name
and msg.d[0].Value
)
$.ajax({
type: "POST",
url: '/Services/Team.asmx/GetClubTeams',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$('#<%= txtFromTeam2.ClientID %>, #<%= txtToTeam2.ClientID %>').autocomplete({
source:msg.d
});
},
error: function(xhr, msg) {
alert(msg);
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答了我自己的问题。诀窍是要知道名称/值应采用以下形式:
public struct TeamData { public string key;公共字符串值; 。
看来
value
(小写)对 jQuery 很重要$.ajax()
调用如下...希望这对某人有帮助:Answered my own question. The trick is to know that the Name/Value should be of the form:
public struct TeamData { public string key; public string value; }
It appears
value
(lowercase) matters to jQuery.The
$.ajax()
call is as follows...hope this helps someone: