×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: A973C FR
Added: Sep 24, 2012 5:34 AM
Views: 40
  1.     $('.link').click(function(){
  2.      
  3.     var params = {'answer' : $(this).attr('answer')};
  4.     var href = $(this).attr('href');
  5.      
  6.     $.post(
  7.     url: href,
  8.     data :params,
  9.     success: function(data){
  10.     switch(data.success){
  11.     case 1: //success
  12.     alert('Correct Response: ' + data.message);
  13.     break;
  14.      
  15.     case 0: //failure
  16.     alert('Incorrect Response: ' + data.message);
  17.     break;
  18.      
  19.     default: //anything else - in this case, an error.
  20.     alert('Error! ' + data.message);
  21.     break;
  22.      
  23.     }
  24.     },
  25.     dataType: 'json'
  26.     );
  27.      
  28.     return false;
  29.     });