test1.html
2.28 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Meine ersten Ajax Erfahrungen</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript">
<!--
var req = null;
function handleTranslation ()
{
switch (req.readyState)
{
case 4:
if (req.status != 200)
alert("Fehler:"+req.status);
else
{
// felder des formulars
german_field = document.getElementById("german");
french_field = document.getElementById("french");
// antwort des servers
var translation = eval('(' + req.responseText + ')');
// schreiben des ergebnisses
german_field.value = translation.german;
french_field.value = translation.french.val1;
}
return true;
default:
return false;
}
}
function translate ()
{
// erstellen des requests
try
{
req = new XMLHttpRequest();
}
catch (e)
{
try
{
req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
req = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (failed)
{
req = null;
}
}
}
if (req == null)
alert("Error creating request object!");
// anfrage erstellen (GET, url ist localhost,
// request ist asynchron
var url = 'http://muedv031/~georg/bilder/ajax+json/ajax.php' +
'?translate=' + document.getElementById ('myword').value;
req.open("GET", url, true);
// Beim abschliessen des request wird diese Funktion ausgeführt
req.onreadystatechange = handleTranslation;
req.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
req.send(null);
}
//-->
</script>
</head>
<body>
<div id="eins" style="width: 80%; height: 80%; border: dashed 1px;">
englisch: <input type="text" id="myword" onchange="translate();" />
<br />
deutsch: <input type="text" id="german" /><br />
französisch: <input type="text" id="french" /><br />
</div>
</body>
</html>