我有下面的腳本似乎不工作。 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