jquery AJAX의 간단한 예제
1 2 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 | <!-- Copyright 2011 jQuery4u.com --> <!DOCTYPE html> <html> <title>jQuery Function Demo - jQuery4u.com</title> <head> <script type= "text/javascript" > 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(); } } } } </script> </head> <body> |