├── README ├── ajaxcontent.html ├── waiting-for-godot.php ├── simple-ajax.js ├── reusable-ajax.js ├── using-proxy.js ├── allowing-link-following.js ├── code.js ├── styles.css ├── proxy.php ├── simple-ajax.html ├── using-proxy.html ├── using-yql.html ├── reusable-ajax.html ├── using-yql.js ├── allowing-link-following.html ├── error-handling.html ├── index.html ├── error-handling.js └── load-external.js /README: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ajaxcontent.html: -------------------------------------------------------------------------------- 1 |
This is some demo content requested by Ajax. I am an awesome coder, me.
-------------------------------------------------------------------------------- /waiting-for-godot.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /simple-ajax.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | $('.ajaxtrigger').click(function(){ 3 | $('#target').load('ajaxcontent.html'); 4 | }); 5 | }); -------------------------------------------------------------------------------- /reusable-ajax.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | $('.ajaxtrigger').click(function(){ 3 | $('#target').load($(this).attr('href')); 4 | return false; 5 | }); 6 | }); -------------------------------------------------------------------------------- /using-proxy.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | $('.ajaxtrigger').click(function(){ 3 | var url = $(this).attr('href'); 4 | if(url.match('^http')){ 5 | url = 'proxy.php?url=' + url; 6 | } 7 | $('#target').load(url); 8 | return false; 9 | }); 10 | }); -------------------------------------------------------------------------------- /allowing-link-following.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | $('.ajaxtrigger').click(function(){ 3 | var url = $(this).attr('href'); 4 | if(url.match('^http')){ 5 | return true; 6 | } else { 7 | $('#target').load(url); 8 | return false; 9 | } 10 | }); 11 | }); -------------------------------------------------------------------------------- /code.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | var url = $('script').last().attr('src'); 3 | $.get(url, 4 | function(code){ 5 | console.log(code); 6 | code=code.replace(/&/mg,'&'); 7 | code=code.replace(//mg,'>'); 9 | code=code.replace(/\"/mg,'"'); 10 | code=code.replace(/\t/g,' '); 11 | code=code.replace(/\r?\n/g,''+code+'');
15 | }
16 | );
17 | });
--------------------------------------------------------------------------------
/styles.css:
--------------------------------------------------------------------------------
1 | *{
2 | margin:0;
3 | padding:0;
4 | }
5 | body{border:2em solid #fff;font-family:futura,verdana,sans-serif;}
6 | a{color:#369}
7 | ul{margin:1em}
8 | h1{font-size:25px;color:#036;}
9 | h2{font-size:18px;margin:10px 0;color:#69c;}
10 | #target,#code{
11 | border:1px solid #999;
12 | background:#eee;
13 | padding:1em;
14 | -moz-border-radius:5px;
15 | border-radius:5px;
16 | -webkit-border-radius:5px;
17 | }
18 | #target{
19 | overflow:auto;
20 | max-height:200px;
21 | }
22 | #ft{font-size:12px;text-align:right;}
23 | .ajaxtrigger span{font-weight:bold;color:#000}
24 | .ajaxtrigger span.error{color:#c00}
25 |
--------------------------------------------------------------------------------
/proxy.php:
--------------------------------------------------------------------------------
1 | ]*>/msi','',$output);
14 | $content = preg_replace('/<\/body>.*/msi','',$content);
15 | $content = preg_replace('/\/body[^>]*>/msi','',$content);
16 | $content = preg_replace('/[\r|\n]+/msi','',$content);
17 | $content = preg_replace('/<--[\S\s]*?-->/msi','',$content);
18 | $content = preg_replace('/