Mercurial > public > sg101
comparison media/js/downloads/rating.js @ 150:b43e1288ff80
Fix #33; use $.ajax instead of $.post so we can handle errors. Also, for some reason comparing objects in a template doesn't work now. Have to compare id fields.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 17 Dec 2009 04:14:16 +0000 |
parents | dbd703f7d63a |
children | 2ba1a6d3b984 |
comparison
equal
deleted
inserted
replaced
149:ab7830b067b3 | 150:b43e1288ff80 |
---|---|
24 { | 24 { |
25 var star = $(this); | 25 var star = $(this); |
26 var id = star.attr('id'); | 26 var id = star.attr('id'); |
27 if (id.match(/star-(\d+)-(\d+)/)) | 27 if (id.match(/star-(\d+)-(\d+)/)) |
28 { | 28 { |
29 $.post('/downloads/rate/', { id: RegExp.$1, rating: parseInt(RegExp.$2) + 1}, | 29 $.ajax({ |
30 function(rating) { | 30 url: '/downloads/rate/', |
31 type: 'POST', | |
32 data: { id: RegExp.$1, rating: parseInt(RegExp.$2) + 1}, | |
33 dataType: 'text', | |
34 success: function(rating) { | |
31 rating = parseFloat(rating); | 35 rating = parseFloat(rating); |
32 if (rating < 0) | 36 if (rating < 0) |
33 { | 37 { |
34 alert("You've already rated this download."); | 38 alert("You've already rated this download."); |
35 return; | 39 return; |
59 s.attr('src', '/static/downloads/stars/rating_off.gif'); | 63 s.attr('src', '/static/downloads/stars/rating_off.gif'); |
60 s.addClass('off') | 64 s.addClass('off') |
61 } | 65 } |
62 } | 66 } |
63 }, | 67 }, |
64 'text'); | 68 error: function (xhr, textStatus, ex) { |
69 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + | |
70 xhr.responseText); | |
71 } | |
72 }); | |
65 } | 73 } |
66 } | 74 } |
67 | 75 |
68 $(document).ready(function() { | 76 $(document).ready(function() { |
69 $('.rating').each(function(n) { | 77 $('.rating').each(function(n) { |