Advertisement
Guest User

Untitled

a guest
Jun 29th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <script type="text/javascript">
  2. $(document).ready(function () {
  3. function voteAjax(pid, vurl, value) {
  4. // Show a loading gif or something
  5. // $(".loading").show(); .hide();
  6. $.ajax({
  7. url: vurl,
  8. type: "GET",
  9. data: { vote: value, id: pid },
  10. success: function (data) {
  11. if (data.success) {
  12. // All went well, say thanks
  13. $('#vote-display').html(data.displayValue);
  14. } else {
  15. // show ex error
  16. }
  17. },
  18. error: function (err) {
  19. // the call thrown an error
  20. },
  21. complete: function () {
  22. // Hide loading gif
  23. }
  24. });
  25. }
  26. $('#vote-up').click(function () {
  27. var pid = $(this).attr("data-pid");
  28. var value = 1;
  29. var vurl = '@Url.Action("VotePost", "Services")';
  30.  
  31. $.ajax({
  32. url: vurl,
  33. type: "GET",
  34. data: { vote: value, id: pid },
  35. success: function (data) {
  36. if (data.success) {
  37. // All went well, say thanks
  38. $('#vote-display').html(data.displayValue);
  39. } else {
  40. // show ex error
  41. }
  42. },
  43. error: function (err) {
  44. // the call thrown an error
  45. },
  46. complete: function () {
  47. // Hide loading gif
  48. }
  49. });
  50. });
  51. $('#vote-down').click(function() {
  52. var pid = $(this).attr("data-pid");
  53. var value = -1;
  54. var vurl = '@Url.Action("VotePost", "Services")';
  55.  
  56. voteAjax(pid, vurl, value);
  57. });
  58. });
  59. </script>
  60.  
  61. @foreach (var post in Model.Posts)
  62. {
  63. <div class="row">
  64. <div class="col-md-1 vote-i">
  65. <a id="vote-up" data-pid="@post.PostID" class="glyphicon glyphicon-chevron-up vote-up"></a><br />
  66. <span id="vote-display">@Html.DisplayFor(modelPost => post.Vote.Value)</span><br/>
  67. <a id="vote-down" data-pid="@post.PostID" class="glyphicon glyphicon-chevron-down vote-down"></a><br/>
  68. </div>
  69. </div>
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement