/* * 検索結果を配列に挿入 * @param id 検索元 */ var target_list = { 'sampletype' : 'scientificname', 'scientificname' : 'tissueorgan', 'collectionregion' : 'collectioncountry', 'chemicalgroups' : 'chemicalname' }; var selected_list = { 'sampletype' : '', 'scientificname' : '', 'collectionregion' : '', 'chemicalgroups' : '' }; function search_ajax (id) { // POSTするデータを生成 var post_data = {}; post_data [id] = $("#" + id).val(); post_data ["_token"] = "GhBOzGxoTulJ8ZofR6pWnzLERoyg1rj7g39oWL8l"; //次の問題取得 var result = new $.ajax({ url: "https://www.chem-theatre.com/select_item", type: "POST", data: post_data, cache: false, dataType: "JSON", // complete: this.setJson, async: false //同期設定 }).responseText; //分解 var json_value = JSON.parse (result); if (json_value ["err"] == "error") { // alert ("no results"); //選択肢入れ替え var doc = $("#" + target_list [id]).get(0); doc.length = 1;//空白分 doc.options [0] = new Option ("-", ""); } else { //選択肢入れ替え var doc = $("#" + target_list [id]).get(0); doc.length = json_value ["value"].length + 1;//空白分を追加 doc.options [0] = new Option ("-", ""); for (var cnt = 0; cnt < json_value ["value"].length; cnt++) { var value = json_value ["value"][cnt]; var text = json_value ["text"][cnt]; doc.options [cnt + 1] = new Option (value, text); if (htmlspecialchars(value).trim() == selected_list[id].trim()) { doc.options [cnt + 1].selected = true; } } } //Sample Type 変更時に Tissue / Organ を初期化 if (id == "sampletype") { //選択肢初期化 var doc = $("#tissueorgan").get(0); doc.length = 1;//空白分 doc.options [0] = new Option ("-", ""); } } function htmlspecialchars(str) { str = str.replace(/&/g, "&"); str = str.replace(//g, ">"); str = str.replace(/'/g, "'"); str = str.replace(/"/g, """); return str; }