Created
August 29, 2012 01:09
-
-
Save romeoh/3505818 to your computer and use it in GitHub Desktop.
XMLHttpRequest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<head></head> | |
<body> | |
</body> | |
<script type="text/javascript"> | |
window.addEventListener("load", init, false); | |
function init(){ | |
var arr = new Array(); | |
var obj = {"key":"value"}; | |
for(var i=0; i<10; i++){ | |
arr.push(obj) | |
} | |
ajax("arr"); | |
ajax(arr); | |
ajax(obj); | |
} | |
function ajax(param){ | |
if(typeof param == "string"){ | |
console.log("string"); | |
}else if(param instanceof Array){ | |
console.log(param); | |
}else if(param instanceof Object){ | |
console.log(param); | |
} | |
} | |
function connectServer(_trCode, _sendData){ | |
if(window.XMLHttpRequest) xmlhttp = new XMLHttpRequest(); | |
else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
xmlhttp.open("POST", "http://124.139.211.101/utims_dev/interface.do", true); //비동기 false = 동기 | |
xmlhttp.onreadystatechange = function (aEvt) { | |
if(xmlhttp.readyState == 4){ | |
if(xmlhttp.status == 200){ | |
console.log(JSON.parse(aEvt.currentTarget.response).body); | |
}else if(xmlhttp.status == 403){ | |
console.log("접근거부"); | |
}else if(xmlhttp.status == 404){ | |
console.log("페이지없음"); | |
}else if(xmlhttp.status == 500){ | |
console.log("서버오류"); | |
} | |
} | |
} | |
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8"); | |
xmlhttp.setRequestHeader("user_data_type", "json"); | |
xmlhttp.setRequestHeader("user_data_enc", "n"); | |
//xmlhttp.setRequestHeader("service_code", "dummy"); | |
xmlhttp.setRequestHeader("user_com_code", "UTIMS.SRVC_FF_GETBLDNGLST2"); | |
var jsonData = { | |
"head":{ | |
"device_md": "SHW-M110S", | |
"app_name": "Morpheus App", | |
"system_version": "2.3", | |
"app_version": "1.0.0.0", | |
"system_name": "Android", | |
"device_id": "123456789", | |
"callback_request_data_flag": "N", | |
"callback_function": "", | |
"phone_no": "010-1234-5678", | |
"user_id": "", | |
"page_name": "", | |
"packet_seq": "", | |
"user_name": "", | |
"appid": "kr.co.morpheus.mobile", | |
"screen_id": "MENU_ID_001" | |
}, | |
"body":{ | |
"i_bldng_dvsn_cd": "01", | |
"i_bs_nm_cd": "", | |
"i_emp_no": "2000987", | |
"i_gubun": "1", | |
"i_mng_pstn_cd": "661900", | |
"i_pda_serno": "FFFFFFFFFF", | |
"i_self_dept_cd": "661900", | |
"i_trln_cd": "27" | |
} | |
} | |
xmlhttp.send(JSON.stringify(jsonData)); | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment