我的问题:我在绑定Wcf响应时无法读取属性length
,但我可以在Wcf服务中获得响应。下面的代码用于文本框中的自动完成。
function AutoCompleteProjectName() {
alert('AutoCompleteProjectName');
var projectname = $('#<%= txtProject.ClientID %>').val();
alert(projectname);
$(".autosuggest").autocomplete({
source: function (request, response) {
alert('ajax cal');
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: serviceUrl + "admin/AddTask.svc/AutoCompleteProjectName",
data: JSON.stringify({ "projectname": projectname, "empno": 1 }),
dataType: "json",
success: function (data) {
response($.map(data.d, function (item) {
console.log("data" + JSON.stringify(item));
return {
label: item.split('/')[0],
val: item.split('/')[1]
}
}));
},
error: function (result) {
alert("Error");
}
});
},
select: function (event, ui) {
$('#<%= hdfldProjectId.ClientID %>').val(ui.item.val);
var hd = $('#<%= hdfldProjectId.ClientID %>').val();
alert(hd);
}
});
}