Hi guys.
Got some trouble with this stuff. Everytime I get an error if I want to start my request. Code:
ajax.js
// HTML5 moofoo runtime.
//
// Copyright 2011 Indiepath Ltd, all rights reserved.
// No warranty implied; use at your own risk.
//***** moofooStream class *****
function mfStrm(){};
mfStrm.prototype.getUrl=function( host, query ){
var self = this;
var xhr = new XMLHttpRequest();
if(xhr==null){
self.onRequestError("Failed to create Request");
};
xhr.open("GET", host + query, true);
xhr.onreadystatechange = function() {
switch (xhr.readyState){
case 0:
self.onRequestError("Error: "+xhr.statusText);
break;
case 1:
self.onConnectionEstablished();
break;
case 2:
self.onRequestReceived();
break;
case 3:
self.onRequestProcessing();
break;
case 4:
if (xhr.status == 200){
self.onRequestComplete(xhr.responseText);
} else {
self.onRequestError("Error: "+xhr.statusText);
}
break;
}
};
xhr.send(null);
};
mfStrm.prototype.onRequestError=function(status){};
mfStrm.prototype.onConnectionEstablished=function(){};
mfStrm.prototype.onRequestReceived=function(){};
mfStrm.prototype.onRequestProcessing=function(){};
mfStrm.prototype.onRequestComplete=function( response ){};
monkey code:
' Module moofoo.stream
'
' Copyright 2011 Indiepath Ltd, all rights reserved.
' No warranty implied; use at your own risk.
Import "ajax.js"
Extern
Class moofooStream="mfStrm"
Method getUrl( host$, query$)
Method onRequestError:String(status:String)
Method onConnectionEstablished:String()
Method onRequestReceived:String()
Method onRequestProcessing:String()
Method onRequestComplete:String(response$)
End
Public
Class asyncStream Extends moofooStream
Method New()
End
Method onRequestError$(status:String)
Print status
End
Method onConnectionEstablished$()
Return "connection made"
End
Method onRequestReceived$()
Return "request received"
End
Method onRequestProcessing$()
Return "request processing"
End
Method onRequestComplete$(response$)
Print response
End
End
Function Main()
Local tmp:asyncStream = New asyncStream
tmp.getUrl("http://localhost/test/index.php", "")
End
The file "index.php" in "/test" definitely exists but I´ll get an error without any text. xhr.status is 0.
May someone can explain what´s going wrong here.
Mfg Suco
|