| 12
 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
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 
 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title></title>
 
<style type="text/css">
body { margin:0; padding:0; }
</style>
 
<script type="text/javascript" src="http://developer.yahoo.com/yui/build/yahoo/yahoo.js"></script>
<script type="text/javascript" src="http://developer.yahoo.com/yui/build/event/event.js"></script>
<script type="text/javascript" src="http://developer.yahoo.com/yui/build/connection/connection.js"></script>
 
<!--begin custom header content for this example-->
<style>
#container {min-height:15em;}
#container li {margin-left:2em;}
</style>
 
<!--end custom header content for this example-->
 
</head>
 
<body>
<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->
 
<form>
<input type="button" onClick="makeRequest();" value="Send a Request">
</form>
 
<div id="container"></div>
<script>
var div = document.getElementById('container');
 
var transactionObject = {
	start:function(type, args){
		YAHOO.log("Custom Event *start* fired for transaction" + args[0].tId + ".", "info", "example");
		div.innerHTML += "<li>Transaction " + args[0].tId + " " + type + " event fired.</li>";
	},
 
	complete:function(type, args){
		YAHOO.log("Custom Event *complete* fired for transaction" + args[0].tId + ".", "info", "example");
		div.innerHTML += "<li>Transaction " + args[0].tId + " " + type + " event fired.</li>";
	},
 
	success:function(type, args){
		YAHOO.log("Custom Event *success* fired for transaction" + args[0].tId + ".", "info", "example");
		div.innerHTML += "<li>Transaction " + args[0].tId + " " + type + " event fired.</li>";
		if(args[0].responseText !== undefined){
			div.innerHTML += "<li>Transaction id: " + args[0].tId + "</li>";
			div.innerHTML += "<li>HTTP status: " + args[0].status + "</li>";
			div.innerHTML += "<li>Status code message: " + args[0].statusText + "</li>";
			div.innerHTML += "<li>HTTP headers: " + args[0].getAllResponseHeaders + "</li>";
			div.innerHTML += "<li>Server response: " + args[0].responseText + "</li>";
			div.innerHTML += "<li>Argument object: Array ( [foo] => " + args[0].argument[0] +" [bar] => " + args[0].argument[1] +" )</li>";
			}
	},
 
	failure:function(type, args){
		YAHOO.log("Custom Event *failure* fired for transaction" + args[0].tId + ".", "info", "example");
		div.innerHTML += "<li>Transaction " + args[0].tId + " " + type + " event fired.</li>";
		if(args[0].responseText !== undefined){
			div.innerHTML += "<li>Transaction id: " + args[0].tId + "</li>";
			div.innerHTML += "<li>HTTP status: " + args[0].status + "</li>";
			div.innerHTML += "<li>Status code message: " + args[0].statusText + "</li>";
		}
	},
 
	abort:function(type, args){
		YAHOO.log("Custom Event *abort* fired for transaction" + args[0].tId + ".", "info", "example");
		div.innerHTML += "<li>Transaction " + args[0].tId + " " + type + " event fired.</li>";
	}
};
 
var handleSuccess = function(o){
	div.innerHTML += "<li>Success response handler triggered in callback.success</li>";
};
 
var handleFailure = function(o){
	div.innerHTML += "<li>Failure response handler triggered in callback.success</li>";
};
 
var callback = {
	success:handleSuccess,
	failure:handleFailure,
	customevents:{
		onStart:transactionObject.start,
		onComplete:transactionObject.complete,
		onSuccess:transactionObject.success,
		onFailure:transactionObject.failure,
		onAbort:transactionObject.abort
	},
 	argument:["foo","bar"]
};
 
function makeRequest(){
	var sUrl = "test.asp";
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
};
</script>
<!--END SOURCE CODE FOR EXAMPLE =============================== -->
 
</body>
</html> | 
Partager