Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
<html>
<head>
<script type="text/javascript">
try{
req = new XMLHttpRequest();
} catch (e){
try{
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e){
try{
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed){
req = null;
}
}
}
function checkInput() {
req.open("GET", 'check.php?text=' + document.form1.text.value, true);
req.onreadystatechange = function(){
switch(req.readyState) {
case 4:
if(req.status!=200) {
alert("Fehler:"+req.status);
}else{
if(req.responseText == "1") {
document.form1.submit(); //Prüfung erfolgreich -> Feuer!
} else {
alert("Du hast nicht \"Hallo\" eingegeben!");
}
}
break;
default:
return false;
break;
}
};
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(null);
return false; // wichtig, damit das Formular nicht abgesendet wird
}
</script>
</head>
<body>
<?php
if(isset($_POST['text'])) {
echo "<p>Formular mit Wert \"" . $_POST['text'] . "\" gesendet.</p>";
}
?>
<form name="form1" action="test.php" method="post" onsubmit="return checkInput();">
<input type="text" size="10" name="text">
<input type="submit" value="ab dafür">
</form>
</body>
</html>
<?php
if(isset($_GET['text']) && $_GET['text'] == "Hallo") {
echo "1";
} else {
echo "0";
}
?>
<script type="text/javascript">
function pdf() {
document.form.action = "pdf.php";
document.form.target = "_blank";
}
try {
req = new XMLHttpRequest();
} catch (e) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e){
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed){
req = null;
}
}
}
function checkInput() {
req.open("GET", 'check.php', true);
req.onreadystatechange = function() {
switch(req.readyState) {
case 4:
if(req.status!=200) {
alert("Fehler:"+req.status);
} else {
if(req.responseText == "1") {
document.form.action = "send.php";
document.form.target = "_self";
} else {
alert("Bitte vorerst das PDF erstellen! ");
}
}
break;
default:
return false;
break;
}
};
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(null);
return false; // wichtig, damit das Formular nicht abgesendet wird
}
</script>
<form name="form" action="" method="post" target="">
<input ... />
<input ... />
<input ... />
<input name="PDF" type="submit" value="PDF erstellen" onclick="javascript:pdf();" />
<input name="submit" type="submit" value="senden" onclick="javascript:checkInput();" />
</form>
<?php
if(file_exists($_POST["name"].'.pdf')) {
echo "1";
} else {
echo "0";
}
?>
function checkInput() {
req.open("GET", 'check.php?name=' + document.form.name.value, true);
...
}
Fehler: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://www.xyz.de/form.php :: anonymous :: line 32" data: no]
Quelldatei: http://www.xyz.de/form.php
Zeile: 32
<input name="submit" type="submit" value="senden" onclick="return checkInput();" />