Title / Description
Code var JQFUNCS = { runFunc: { /* ------------------------------ ajax Demo ------------------------------ */ "ajax": { run: function(id) { $('#'+id+' .content1').bind('click', function(e) { e.preventDefault(); getContent('/function-demos/functions/ajax/data/content1.html'); }); $('#'+id+' .content2').bind('click', function(e) { e.preventDefault(); getContent('/function-demos/functions/ajax/data/content2.html'); }); $('#'+id+' .content3').bind('click', function(e) { e.preventDefault(); getContent('/function-demos/functions/ajax/data/content3.html'); }); function getContent(filename) { $.ajax({ url: filename, type: 'GET', dataType: 'html', beforeSend: function() { $('#'+id+' .contentarea').html('<img src="/function-demos/functions/ajax/images/loading.gif" />'); }, success: function(data, textStatus, xhr) { if (filename == '/function-demos/functions/ajax/data/content3.html') { setTimeout( function() { $('#'+id+' .contentarea').html(data); }, 2000); } else { $('#'+id+' .contentarea').html(data); } }, error: function(xhr, textStatus, errorThrown) { $('#'+id+' .contentarea').html(textStatus); } }); } }, reset: function(id) { $('#'+id+' .contentarea').html('Content will appear here.'); $('#'+id).hide(); } } } }
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code