// ------------------------------------------------------------
// XMLHttpRequest オブジェクトを作成する関数
// ------------------------------------------------------------
function XMLHttpRequestCreate(){
try{
return new XMLHttpRequest();
}catch(e){}
try{
return new ActiveXObject('MSXML2.XMLHTTP.6.0');
}catch(e){}
try{
return new ActiveXObject('MSXML2.XMLHTTP.3.0');
}catch(e){}
try{
return new ActiveXObject('MSXML2.XMLHTTP');
}catch(e){}
return null;
}
function getHttp(url){
var domain = document.domain;
url = 'https://'+domain+url;
var req = XMLHttpRequestCreate();
req.onreadystatechange = function (){
switch(req.readyState){
case 4:
if(req.status == 0){
}else{
if((200 <= req.status && req.status < 300) || (req.status == 304)){
}
}
break;
}
};
req.open('GET', url, false);
req.send();
var ret = req.response;
req.abort();
return ret;
}
function post(url, postData, elm){
var domain = document.domain;
url = 'https://'+domain+url;
var req = XMLHttpRequestCreate();
req.open("POST" , url, true);
req.onreadystatechange = function (){
switch(req.readyState){
case 4:
if(req.status == 0){
}else{
if((200 <= req.status && req.status < 300) || (req.status == 304)){
if(document.getElementById(elm) != null){
document.getElementById(elm).innerHTML = req.responseText;
}else{
alert(req.responseText);
}
}
}
break;
}
};
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.send(postData);
}
function dbUp(url, postData, elm){
var domain = document.domain;
url = 'https://'+domain+url;
var req = XMLHttpRequestCreate();
req.open("POST" , url, true);
req.onreadystatechange = function (){
switch(req.readyState){
case 4:
if(req.status == 0){
}else{
if((200 <= req.status && req.status < 300) || (req.status == 304)){
if(req.responseText){
alert("登録しました");
document.getElementById(elm).value = req.responseText;
}else{
alert("更新しました");
}
}
}
break;
}
};
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.send(postData);
}
function get(url, elm){
var domain = document.domain;
url = 'https://'+domain+url;
var req = XMLHttpRequestCreate();
req.open("GET" , url);
req.onreadystatechange = function (){
switch(req.readyState){
case 4:
if(req.status == 0){
}else{
if((200 <= req.status && req.status < 300) || (req.status == 304)){
if(document.getElementById(elm) != null){
document.getElementById(elm).innerHTML = req.responseText;
}else{
alert(req.responseText);
}
}
}
break;
}
};
req.send();
}
function postRemove(url, elm){
var domain = document.domain;
url = 'https://'+domain+'/'+url;
var req = XMLHttpRequestCreate();
req.open("GET" , url);
req.onreadystatechange = function (){
switch(req.readyState){
case 4:
if(req.status == 0){
}else{
if((200 <= req.status && req.status < 300) || (req.status == 304)){
alert("削除しました");
}
}
break;
}
};
req.send();
}
// ------------------------------------------------------------
// XMLHttpRequest オブジェクトを作成
// ------------------------------------------------------------
var xhr = XMLHttpRequestCreate();
// ------------------------------------------------------------
// XHR 通信の状態が変化するたびに実行されるイベント
// ------------------------------------------------------------
xhr.onreadystatechange = function (){
switch(xhr.readyState){
case 4:
// ------------------------------------------------------------
// XHR 通信失敗
// ------------------------------------------------------------
if(xhr.status == 0){
alert("XHR 通信失敗");
// ------------------------------------------------------------
// XHR 通信成功
// ------------------------------------------------------------
}else{
// ------------------------------------------------------------
// リクエスト成功
// ------------------------------------------------------------
if((200 <= xhr.status && xhr.status < 300) || (xhr.status == 304)){
alert("変更しました。");
// ------------------------------------------------------------
// リクエスト失敗
// ------------------------------------------------------------
}else{
//alert("その他の応答:" + xhr.status);
}
}
break;
}
};
// ------------------------------------------------------------
// 「POST メソッド」「接続先 URL」を指定
// ------------------------------------------------------------
//var url = "http://example.com/test.cgi";
//xhr.open("POST" , url);
// ------------------------------------------------------------
// 「送信データ」を指定、XHR 通信を開始する
// ------------------------------------------------------------
//var send_data = "送信テスト";
//xhr.send(send_data);
function page_send(element){
var target = document.getElementById(element);
target.method = "post";
target.submit();
}
function triggerEvent(element, event) {
if (document.createEvent) {
// IE以外
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true ); // event type, bubbling, cancelable
return element.dispatchEvent(evt);
} else {
// IE
var evt = document.createEventObject();
return element.fireEvent("on"+event, evt)
}
}