Nachdem nun das vB 3.5 damit arbeitet und das wBB 3.0 zu 100%iger Sicherheit mitziehen wird, habe ich mich mal drangesetzt und mein erstes Game damit Programiert.
Hier einfach nur mal die Routine:
|
PHP Source code
|
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
|
var xmlhttp;
function XHCon(sURL, sMethod, sVars) {
xmlhttp = false;
if(window.XMLHttpRequest) {
try {
xmlhttp = new XMLHttpRequest();
} catch(e) {
xmlhttp = false;
}
} else if(window.ActiveXObject) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
xmlhttp = false;
}
}
}
if (xmlhttp) {
sMethod = sMethod.toUpperCase();
xmlhttp.onreadystatechange = processReqChange;
if (sMethod == "GET") {
xmlhttp.open(sMethod, sURL + "?" + sVars, true);
sVars = "";
} else {
xmlhttp.open(sMethod, sURL, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}
xmlhttp.send(sVars);
return true;
}
return false;
}
function processReqChange() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) { // ... URL is OK
AJAXreturn = xmlhttp.responseText; // Rückgabe aus der PHP (echo "......")
alert(xmlhttp.responseText); // nur um zu zeigen was zurück kommt
}
} else {
alert("URL doesn't exist ...");
}
}
}
|
Der eigentliche Aufruf erfolgt dann z.B. mit:
|
PHP Source code
|
1
2
3
4
5
6
7
8
|
var sendVars = "action=testme;
var stat = XHCon("meine_ajax.php", "POST", sendVars);
if (!stat) {
sendVars += "&dont=noajax";
var newURL = "meine.php?" + sendVars;
top.location.href = newURL;
top.location.focus();
}
|
stat ist TRUE, wenn erfolgreich - ansonsten FALSE
dann springe ich in eine andere PHP, wo ich den POST abfange und den Browser manuell refreshe.
Grüße
Snoopy