Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added ajax methods for PrototypeJS

  • Loading branch information...
commit c5fc9184ec383c0faeba787694062bf03f85a128 1 parent 0d5130e
Joe Crawford authored
Showing with 52 additions and 1 deletion.
  1. +52 −1 prototype.html
53 prototype.html
View
@@ -70,6 +70,57 @@
item.down('span').update(spanStr);
});
});
+
+ // Load HTML with Ajax
+ $('ajaxloadHtml').observe('click', function(evt){
+ var url = 'ajax/chunk.html';
+ new Ajax.Request(url, {
+ method: 'get',
+ onSuccess: function(transport) {
+ $('ajaxOutput').update(transport.responseText);
+ }
+ });
+ Event.stop(evt);
+ });
+
+ // Load text with Ajax
+ $('ajaxloadText').observe('click', function(evt){
+ var url = 'ajax/chunk.txt';
+ new Ajax.Request(url, {
+ method: 'get',
+ onSuccess: function(transport) {
+ $('ajaxOutput').update(transport.responseText);
+ }
+ });
+ Event.stop(evt);
+ });
+
+ // Load JSON with Ajax
+ $('ajaxloadJson').observe('click', function(evt){
+ var url = 'ajax/chunk.json';
+ new Ajax.Request(url, {
+ method: 'get',
+ evalJSON: 'force',
+ onSuccess: function(transport) {
+ $('ajaxOutput').update(transport.responseJSON.txt);
+ }
+ });
+ Event.stop(evt);
+ });
+
+ // Load XML with Ajax
+ $('ajaxloadXml').observe('click', function(evt){
+ var url = 'ajax/chunk.xml';
+ new Ajax.Request(url, {
+ method: 'get',
+ onSuccess: function(transport) {
+ var node = transport.responseXML.documentElement.getElementsByTagName('text')[0];
+ $('ajaxOutput').update(node.firstChild.data);
+ }
+ });
+ Event.stop(evt);
+ });
+
var sourceCode = $$('script')[2];
$('code').innerHTML = sourceCode.innerHTML;
@@ -108,7 +159,7 @@
<a href="#" id="ajaxloadJson">json</a> &middot;
<a href="#" id="ajaxloadText">text</a> &middot;
<a href="#" id="ajaxloadXml">xml</a>:
- <div id="ajaxOutput">AJAX Examples are not yet implemented.</div>
+ <div id="ajaxOutput">Load data into this by clicking the links above.</div>
</div>
<div id="randomContent">
Please sign in to comment.
Something went wrong with that request. Please try again.