/** * @file ajax_base.js * @brief Ajaxを扱う上で必要関数を纏めたファイルです */ /** * @brief XMLHttpRequestオブジェクトを生成する関数 */ function getHttpObject() { var xml_http; if(window.ActiveXObject){ try{ // IE6 xml_http = new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ try{ // IE4 または IE5 xml_http = new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ xml_http = false; } } }else if(window.XMLHttpRequest){ try{ // IE以外のブラウザ xml_http = new XMLHttpRequest(); }catch(e){ xml_http = false; } } return xml_http; } /** * @brief ファイルオープン関数(GET形式) * いずれPOST形式も加えるだろうで関数化 * @param open_file_st 開くファイル名 * @param http_obj XMLHttpRequestオブジェクト */ function openFile(open_file_st, http_obj) { http_obj.open("GET", open_file_st, true); } /** * @brief カレンダーメイン関数 * @param year 年 (ex: 2007) * @param mon 月 (ex: 1月の場合→1) * @param day 日 (ex: 1日の場合→1) */ function calMain(year, mon, day) { // オブジェクト生成 var http_obj = getHttpObject(); // 読み込むファイル名 var file_st = '/abroad-tour/calendar.html?cal_dy=' + year + '&cal_dm=' + mon + '&cal_dd=' + day; openFile(file_st, http_obj); // 文字化け対策(文字コード指定とキャッシュを消す) http_obj.setRequestHeader('Content-Type', 'utf-8'); http_obj.setRequestHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); var id = getOpenPopId(); // レスポンスの受信状態の確認 → 受信完了ならカレンダー処理 http_obj.onreadystatechange = function() { // データ受信完了判定 if (http_obj.readyState == 4 && http_obj.status == 200) { if (id != 'atour_cal') { if (id != '') { deletePopWindow(id); } setOpenPopId('atour_cal'); } document.getElementById("atour_cal").innerHTML = measureGarbleText(http_obj); document.getElementById("atour_cal").style.display = 'block'; // zindex対応 setZindex(1); } } http_obj.send(null); setTimeout(function () { hiddenObject('atour_cal', 1); },10); } /** * @breaf カレンダーから選ぶをクリックした際のみ走る関数 * Ajaxを扱うcalMainに余分な処理を入れたくなかったので * 別途関数宣言。 * プルダウンの中身を検知し、calMainへと遷移 */ function createCalendar() { var id = getOpenPopId(); if (document.getElementById("atour_cal").style.display == 'block') { deletePopWindow('atour_cal'); setOpenPopId(''); } else { var form_obj = document.OPS_SEARCH; var year = ''; var mon = ''; var day = ''; // 年検知 year = form_obj.dy.options[form_obj.dy.selectedIndex].value; if (form_obj.dm.selectedIndex > 0) { // 月検知 mon = form_obj.dm.options[form_obj.dm.selectedIndex].value; }else{ mon = 0; } if (form_obj.dm.selectedIndex > 0 && form_obj.dd.selectedIndex > 0) { // 日検知 day = form_obj.dd.options[form_obj.dd.selectedIndex].value; } else { day = 0; } calMain(year, mon, day); } } /** * @brief 文字化け対策 * @param http_obj XMLHttpRequestオブジェクト * @return response_text 文字化け対策を施したテキスト */ function measureGarbleText(http_obj) { var response_text = http_obj.responseText; if (navigator.appVersion.indexOf("KHTML") > -1) { var esc = escape(response_text); if (esc.indexOf("%u") < 0 && esc.indexOf("%") > - 1) { response_text = decodeURIComponent(esc); } } return response_text; }