‹• ⊂⌈α⊂κ¥ •›
RANG Deckschrubber
|
#1 - 14.08 09:54
Hi all, hab nen problem.
Schreibe mir grade eine js klasse für meine ajax requests.
Das ganze sieht zur zeit so aus:
code: |
/*
Javascript ajax class
*/
function ajax_object(){
this.ajaxObject = false;
this.debug = true;
this.method = 'post';
if(window.XMLHttpRequest)
this.ajaxObject = new XMLHttpRequest(); // mozilla, safari, opera
else if(window.ActiveXObject){ // Now IE
try{
this.ajaxObject = new ActiveXObject('Msxml2.XMLHTTP'); // IE5
} catch (e){
try{
this.ajaxObject = new ActiveXObject('Microsoft.XMLHTTP'); // IE6
} catch (e) {
if(this.debug == true){
alert("Debug: Can't create XMLHttpRequest!\nException: " + e);
return false;
}
}
}
}
}
// Create a request to server script
ajax_object.prototype.request = function(url){
if(!this.ajaxObject){ // No ajaxObject
if(this.debug == true)
alert("Debug: No ajax object given!");
return false;
} else if(!url) { // Request URL missed
if(this.debug == true)
alert("Debug: No request-url given!");
return false;
} else { // Ok, all given! Now do the request
this.ajaxObject.open(this.method, url);
this.ajaxObject.send(null);
this.ajaxObject.onreadystatechange = ajaxObject.interpretRequest(this.ajaxObject);
}
}
// This method can interpret the response
ajax_object.prototype.interpretRequest = function(ajaxObject){
alert(ajaxObject.readyState);
switch(ajaxObject.readyState){
// only if ready state == 4 and status == 200 all is ok!
case 4:
alert("4");
if(this.ajaxObject.status != 200){
if(this.debug == true)
alert("Debug: Request done but with problems!\nError: " + this.ajaxObject.status);
return false;
} else {
alert("all ok");
return this.ajaxObject.reponseText;
}
break;
default:
break;
}
}
|
So, das ganze will aber nicht so richtig.
Ich kriege immer nur einen readyState von 1!
Aufruf:
code: |
<html>
<head>
<title>TEST</title>
<script src="javascript/ajax_request.js" language="javascript"></script>
<script>
var ajaxObject = new ajax_object();
ajaxObject.debug = true;
ajaxObject.method = 'GET';
ajaxObject.request("request.php");
//alert(b);
</script>
</head>
<body>
</body>
</html>
|
Wenn ich die open methode synchron setze, kriege ich einen state von 4.
Hat jemand einen tip?
Thx
|