3 changed files with 151 additions and 0 deletions
@ -0,0 +1,55 @@ |
|||||
|
<?php |
||||
|
|
||||
|
$english = mysql_escape_string($_REQUEST['translate']); |
||||
|
// Der Service ist zur Zeit leider deaktiviert....
|
||||
|
// $trans = new SoapClient(
|
||||
|
// "http://www.xmethods.net/sd/2001/BabelFishService.wsdl");
|
||||
|
|
||||
|
/* |
||||
|
try |
||||
|
{ |
||||
|
$german = $trans->BabelFish("en_de",$english); |
||||
|
$french = $trans->BabelFish("en_fr",$english); |
||||
|
} |
||||
|
catch(SoapFault $e) |
||||
|
{ |
||||
|
$english = "not found"; |
||||
|
$german = "not found"; |
||||
|
$french = "not found"; |
||||
|
} |
||||
|
*/ |
||||
|
$encoding = FALSE; |
||||
|
if (isset ($_SERVER['HTTP_ACCEPT_ENCODING']) && |
||||
|
strpos ($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== FALSE) |
||||
|
$encoding = "x-gzip"; |
||||
|
if (isset ($_SERVER['HTTP_ACCEPT_ENCODING']) && |
||||
|
strpos ($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) |
||||
|
$encoding = "gzip"; |
||||
|
|
||||
|
header ('Content-type: text/plain'); |
||||
|
|
||||
|
$result = FALSE; |
||||
|
if ($encoding !== FALSE) |
||||
|
$result = gzcompress (json_encode (array( |
||||
|
"english" => 'doing gzip', |
||||
|
"german" => 'gezipedte Daten', |
||||
|
"french" => 'la zippo'))); |
||||
|
|
||||
|
if ($result !== FALSE) |
||||
|
{ |
||||
|
header ('Content-Encoding: ' . $encoding); |
||||
|
|
||||
|
print ("\x1f\x8b\x08\x00\x00\x00\x00\x00"); |
||||
|
print ($result); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
$result = json_encode (array( |
||||
|
"english" => 'doing no gzip', |
||||
|
"german" => 'nicht gezipedte Daten', |
||||
|
"french" => 'no la zippo')); |
||||
|
|
||||
|
print ($result); |
||||
|
} |
||||
|
|
||||
|
?>
|
||||
@ -0,0 +1,96 @@ |
|||||
|
<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; |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
default: |
||||
|
return false; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
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> |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue