mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-19 16:02:15 +00:00
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
*
|
||||
* HTTP Request Klasse
|
||||
* stammt aus Artikel von phpPatterns (http://www.phppatterns.com/index.php/article/articleview/82/1/2/)
|
||||
* leicht modifiziert
|
||||
*/
|
||||
|
||||
//Configuration Details
|
||||
//const SERVER_URL = "/xul/server.php";
|
||||
// wir uebergeben das als Parameter
|
||||
//End Configuration
|
||||
|
||||
function doLogin() {
|
||||
var username = document.getElementById('loginUser').value;
|
||||
var password = document.getElementById('loginPass').value;
|
||||
|
||||
req = new phpRequest();
|
||||
req.add('username',username);
|
||||
req.add('password',password);
|
||||
|
||||
var response = req.execute();
|
||||
alert(response);
|
||||
}
|
||||
|
||||
//Start phpRequest Object
|
||||
function phpRequest(server_url,uname,passw) {
|
||||
this.parms = new Array();
|
||||
this.parmsIndex = 0;
|
||||
this.execute = phpRequestExecute;
|
||||
this.add = phpRequestAdd;
|
||||
this.server = server_url;
|
||||
this.uname = uname;
|
||||
this.passw = passw;
|
||||
}
|
||||
|
||||
function phpRequestAdd(name,value) {
|
||||
this.parms[this.parmsIndex] = new Pair(name,value);
|
||||
this.parmsIndex++;
|
||||
}
|
||||
|
||||
function phpRequestExecute() {
|
||||
var targetURL = this.server;
|
||||
|
||||
try {
|
||||
var httpRequest = new XMLHttpRequest();
|
||||
}catch (e){
|
||||
alert('Error creating the connection!');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
var txt = "?";
|
||||
for(var i in this.parms) {
|
||||
txt = txt+'&'+this.parms[i].name+'='+this.parms[i].value;
|
||||
}
|
||||
//alert('sende '+txt);
|
||||
//Two options here, only uncomment one of these
|
||||
//GET REQUEST
|
||||
httpRequest.open("GET", targetURL+txt, false, '<?php echo $_SERVER['PHP_AUTH_USER'] ?>','<?php echo $_SERVER['PHP_AUTH_PASSW'] ?>');
|
||||
|
||||
//POST REQUEST EXAMPLE
|
||||
/*
|
||||
httpRequest.open("POST", targetURL+txt, false, null, null);
|
||||
httpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
|
||||
*/
|
||||
httpRequest.send('');
|
||||
|
||||
}catch (e){
|
||||
alert('An error has occured calling the external site: '+e);
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(httpRequest.readyState) {
|
||||
case 1,2,3:
|
||||
alert('Bad Ready State: '+httpRequest.status);
|
||||
return false;
|
||||
break;
|
||||
case 4:
|
||||
if(httpRequest.status !=200) {
|
||||
alert('The server respond with a bad status code: '+httpRequest.status);
|
||||
return false;
|
||||
} else {
|
||||
var response = httpRequest.responseText;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
function Pair(name,value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
Reference in New Issue
Block a user