ajax.js
1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var http_request = false;
function makeRequest(url, functionName, httpType, sendData) {
http_request = false;
if (!httpType) httpType = "GET";
if (window.XMLHttpRequest) { // Non-IE...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/plain');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot send an XMLHTTP request');
return false;
}
var changefunc="http_request.onreadystatechange = "+functionName;
eval (changefunc);
//http_request.onreadystatechange = alertContents;
http_request.open(httpType, url, true);
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http_request.send(sendData);
}
function getReturnedText () {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
var messagereturn = http_request.responseText;
return messagereturn;
} else {
alert('There was a problem with the request.');
}
}
}
function EchoReturnedText () {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
var messagereturn = http_request.responseText;
if(messagereturn!='isfail')
{
var r;
r=messagereturn.split('|');
if(r.length!=1)
{
if(r[0]!='')
{
document.getElementById(r[1]).innerHTML=r[0];
}
if(r[2]!='')
{
alert(r[2]);
}
}
else
{
document.getElementById('ajaxarea').innerHTML=messagereturn;
}
}
} else {
alert('There was a problem with the request.');
}
}
}