this will run tests in the current browser, verifying that the operation returns as expected.
Tests
:
Format:
IO:
myIO("test.txt");
myIO( "GET", "test.txt");
myIO({ url: "test.htm" })
myIO({ url: "test.txt", done:function(data){ window.report(data, a);} });
myIO({ url: "test.xml", good:function(xml){ var xd = xml.getElementsByTagName("data")[0]; window.report(xd.textContent || xd.text , a); } });
myIO({ url: "test.htm", mode:"HEAD", success:function(){ window.report( this.getResponseHeader("Content-Type"), a ); } });
myIO({ url: "test.txt", mode:"HEAD", OnSuccess:function(){ window.report( this.getResponseHeader("Content-Type"), a ); } });
myIO({ cache: true, url: "test.txt", onComplete:function(data){ window.report(data, a);} });
//yahoo-like example: YAHOO.util.Connect.asyncRequest('GET', sUrl, callback); myIO('GET', "test.htm", { success: function(data){window.report(data, a)} });
myIO({ url:"something.thats.gone", error: function(data){ window.report(data.status, a) } });
/* jQuery test: $.ajax({ url: "test.html", cache: false, success: function(html){ $("#results").append(html); } }); */ myIO({ url: "test.htm", cache: false, success: function(html){ window.report(html, a) } });
/* jQuery Test: $.ajax({ url: "some.php", async: false }).responseText; */ myIO({ url: "test.htm", async: false }).responseText;
/* jQuery Test: alternate no-.responseText usage $.ajax({ url: "some.php", async: false }).responseText; */ myIO({ url: "test.htm", async: false });
/* jQuery Test: $.ajax({ url: "test.html", cache: false, success: function(html){ $("#results").append(html); } }); */ myIO({ url: "test.htm", cache: false, success: function(html){ window.report(html, a); } });
/* jQuery Test: $.get("test.php"); */ myIO("test.htm");
/* jQuery Test: $.get("test.php", function(data){ alert("Data Loaded: " + data); }); */ myIO("test.htm", function(data){ window.report(data, a); });
//test complete on fail: myIO({url:"nothing.htm", done:function(data){ window.report("ok", a); } });
myIO("get", "test.htm");
myIO( "test.htm", "get");
/* prototype test: var url = '/proxy?url=' + encodeURIComponent('http://www.google.com/search?q=Prototype'); // notice the use of a proxy to circumvent the Same Origin Policy. new Ajax.Request(url, { method: 'get', onSuccess: function(transport) { var notice = $('notice'); if (transport.responseText.match(/href="http:\/\/prototypejs.org/)) notice.update('Yeah! You are in the Top 10!').setStyle({ background: '#dfd' }); else notice.update('Damn! You are beyond #10...').setStyle({ background: '#fdd' }); } }); */ var url = "test.htm"; myIO(url, { method: 'get', onSuccess: function(transport) { window.report( transport.responseText, a); } });
/*prototype test: new Ajax.Request('/your/url', { onSuccess: function(transport) { // yada yada yada } }); */ myIO('test.htm', { OnGood: function(transport) { window.report( transport, a); } });
/* prototype test new Ajax.Request('/your/url', { onSuccess: function(response) { // Note how we brace against null values if ((response.getHeader('Server') || '').match(/Apache/)) ++gApacheCount; // Remainder of the code } }); */ myIO('test.htm', { onSuccess: function(response) { window.report( this.getResponseHeader('Content-Length'), a); } });
// test each property of string response object myIO('test.htm', { done: function(response) { window.report( response.status , a); }});
//should fail unless response delay is guessed right to the ms myIO('test.htm', { done: function(response) { window.report( response.duration, a); }});
myIO('test.htm', { done: function(response) { window.report( response.responseText, a); }});
myIO('test.htm', { done: function(response) { window.report( response.responseXML, a); }});