ajax 를 처음 배 운 사람 에 게 ajax 함수 코드 를 드 립 니 다.
/*
:
1.POST
var txt = escape(sender.value); //document.getElementById("<%= txtName.ClientID %>").value);
var data = "name=" + txt + "&pwd=" + txt;
var option = { "url": "handler/Handler.ashx"
, "action": "POST"
, "callback": function(){
if (xmlHttp.readyState == 4) {//
if (xmlHttp.status == 200) {//
alert(xmlHttp.responseText);
}
xmlHttp = null; //
}
}
, "data": data
};
ajax(option);
2.GET
var txt = escape(sender.value); //document.getElementById("<%= txtName.ClientID %>").value);
var option = { "url": "handler/Handler.ashx&name=" + txt + "&pwd=" + txt
, "action": "POST"
, "callback": function(){
if (xmlHttp.readyState == 4) {//
if (xmlHttp.status == 200) {//
alert(xmlHttp.responseText);
}
xmlHttp = null; //
}
}
};
ajax(option);
*/
function ajax(option) {
createXMlHttpRequest(); // xmlHttpRequest
if (option != null && option != undefined) {
if (option.url == null && option.url == undefined) {
xmlHttp = null;
alert(" option.url");
return;
}
if (option.action == null && option.action == undefined) {
xmlHttp = null;
alert(" option.action");
return;
}
xmlHttp.open(option.action, option.url, true);
if (option.contentType != null && option.contentType != undefined) {
xmlHttp.setRequestHeader("Content-Type", option.contentType);
} else {
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}
if (option.callback != null && option.callback != undefined) {
xmlHttp.onreadystatechange = option.callback;
}
if (option.action.toUpperCase() == "POST") {
xmlHttp.send(option.data);
} else {
xmlHttp.send(null);
}
}
}
var xmlHttp; // xmlHttp = null;
/* */
function g(arg) {
var t = document.getElementById(arg);
if (null != t && t != undefined) {
return t;
}
t = document.getElementsByName(arg);
if (null != t && t != undefined) {
return t;
}
t = document.getElementsByTagName(arg);
if (null != t && t != undefined) {
return t;
}
}
/* ajax */
function createXMlHttpRequest() {
try {//Firefox, Chrome, Surfri, Opera+8
xmlHttp = new XMLHttpRequest();
}
catch (ie) {
try {//IE6+
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (ie) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Javascript Ajax에 대한 간단한 연습저는 약 4년 동안 프로그래밍 개인 튜터로 일한 경험이 있습니다. 약 5년 전에 " "이라는 제목의 페르시아어로 내 웹사이트에 블로그 게시물을 올렸고 사람들이 저에게 전화하기 시작했습니다. 나는 항상 사람들을 가르치...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.