我有下面的脚本似乎不工作。 aspx页面返回类似json的脚本,在下面的脚本中已经被注释掉了。如果我将这个json直接粘贴到源数组中,它就可以很好地工作。使用asp.net生成json的自动完成
但是,当我尝试使用下面的脚本时,我没有收到任何错误消息或任何内容,当我输入自动填充字段时没有任何反应。
$(document).ready(function(){
$('#button').click(function() {
alert($("#txtAllowSearchID").val());
});
//var $local_source = [ {id:0,value:"c++"}, {id:1,value:"java"}, {id:2,value:"php"}, {id:3,value:"coldfusion"}, {id:4,value:"javascript"}, {id:5,value:"asp"}, {id:6,value:"ruby"} ];
$("#txtAllowSearch").autocomplete({
source: function(request, response) {
$.ajax({
type: "POST",
url: "test_array.aspx",
data: "{'prefixText': '" + $('#txtAllowSearch').val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
response(data.d);
},
failure: function(errMsg) {
$('#errMessage').text(errMsg);
}
});
},
select: function (event, ui) {
$("#txtAllowSearch").val(ui.item.value); // display the selected text
$("#txtAllowSearchID").val(ui.item.id); // save selected id to hidden input
}
});
});
编辑:我认为这个问题是在aspx页面:
objSQLCommand = New SqlCommand("select id, value from table1 where value like '%@prefixText%'", objSQLConnection)
objSQLCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 255).Value = "ing"
如果我只是用th如上所述,如何在.aspx页面返回json数据之前向.aspx页面发布值? – oshirowanen 2011-01-27 14:33:02