オートコンプリートをされていない、本当にすべてが難しいです。まず、返品タイプを設定する必要があります。最も簡単なので、JSON形式にする傾向がある:
PHPコントローラーエンド
// be sure to use echo, not return
echo json_encode($yourDataAsArrayOrObject);
その一部最後に完了戻ってあなたのjavascriptに行く
$("#item").autocomplete({
// source should be a url to the controller function that returns the data
source: 'www.yoursite.com/controller/function',
search: function(e, ui) {}, // here you can manipulate other elements or items while the data is being retrieved,
select: function(e, ui) { /* ui.item is item slected */ } // here you can manipluate things based on the item that was selected, for instance, save a list of sub data to another dom element
});
、警告
// You will need to use ._renderItem to items as they are received by database.
// For instance, if you want to display the dropdown items in a custom way.
$("#item")._renderItem = function(ul, item) {
// the item. depends on the information you got from server
return ul.append($("<li></li>").prepend($("<h3></h3>").text(item.label)).append($("<p></p>").text(item.value)));
};
で
-1を文字列連結として使用すると、有効なJSONが生成されないことがあります。 'reader.GetString(0)'の内容があなたの出力を壊すかもしれない無数の方法を考慮する必要があります。 –
あなたはあなたがやっている各AJAX呼び出しのために別々のASPXページで終わるので、私は真剣に論理をWebメソッドに入れようと考えています...それは大規模なWebアプリケーションで維持する悪夢になります。 – FarligOpptreden
あなたのコードにSQLインジェクションの脆弱性があることを認識していますか? –