/ Published in: jQuery
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$('.link').click(function(){ var params = {'answer' : $(this).attr('answer')}; var href = $(this).attr('href'); $.post( url: href, data :params, success: function(data){ switch(data.success){ case 1: //success alert('Correct Response: ' + data.message); break; case 0: //failure alert('Incorrect Response: ' + data.message); break; default: //anything else - in this case, an error. alert('Error! ' + data.message); break; } }, dataType: 'json' ); return false; });
URL: http://www.dropthenerd.com/ajax-a-simple-approach-that-you-will-use-and-reuse/