mine.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. function Follow(obj,data,url){
  2. if(obj.hasClass('active'))
  3. {$.ajax ({
  4. type : "DELETE",
  5. url : url,
  6. data:data,
  7. contentType: 'application/json;charset=UTF-8',
  8. success: function(result) {
  9. if (result.judge === true)
  10. {
  11. obj.text('关注').removeClass('active');
  12. } else
  13. {alert('fail');}}});
  14. }else
  15. {$.ajax ({
  16. type : "POST",
  17. url : url,
  18. data:data,
  19. contentType: 'application/json;charset=UTF-8',
  20. success: function(result) {
  21. if (result.judge === true)
  22. {
  23. obj.text('取消关注').addClass('active');
  24. } else
  25. {alert('fail');}
  26. }});
  27. }
  28. }
  29. $(document).ready(function(){
  30. $('button.tagfollow').click(function(){
  31. var _$this = $(this);
  32. var url = "/user/follow/tag";
  33. var data = JSON.stringify({
  34. id:_$this.attr("id"),
  35. });
  36. Follow(_$this,data,url);
  37. });
  38. $('button.topicfollow').click(function(){
  39. var _$this = $(this);
  40. var url = "/user/follow/topic";
  41. var data = JSON.stringify({
  42. id:_$this.attr("id"),
  43. });
  44. Follow(_$this,data,url);
  45. });
  46. $('button.collectfollow').click(function(){
  47. var _$this = $(this);
  48. var url = "/user/follow/collect";
  49. var data = JSON.stringify({
  50. id:_$this.attr("id"),
  51. });
  52. Follow(_$this,data,url);
  53. });
  54. $('button.userfollow').click(function(){
  55. var _$this = $(this);
  56. var url = "/user/follow/user";
  57. var data = JSON.stringify({
  58. id:_$this.attr("id"),
  59. });
  60. Follow(_$this,data,url);
  61. });
  62. });
  63. function DoCollect(collectData) {
  64. $(document).ready(function(){
  65. $('button#edit-collect-form').click(function() {
  66. var data = JSON.stringify({
  67. name:$('#name').val(),
  68. description:$('#description').val(),
  69. is_privacy:$("input[name='is_privacy']:checked").val()
  70. });
  71. $.ajax ({
  72. type : "PUT",
  73. url : collectData.collect_action_url,
  74. data:data,
  75. contentType: 'application/json;charset=UTF-8',
  76. success: function(result) {
  77. if (result.judge === true)
  78. {
  79. window.location =collectData.collect_action_url ;
  80. }
  81. }
  82. });
  83. });
  84. $('button#delete-collect-form').click(function() {
  85. $.ajax ({
  86. type : "DELETE",
  87. url : collectData.collect_action_url,
  88. data:JSON.stringify(),
  89. contentType: 'application/json;charset=UTF-8',
  90. success: function(result) {
  91. if (result.judge === true)
  92. {
  93. window.location = collectData.collect_url;
  94. }
  95. }
  96. });
  97. });
  98. $('#delete-from-collect').click(function() {
  99. var _$this = $(this);
  100. var topicId = _$this.attr('data-id');
  101. var data = JSON.stringify({
  102. topicId:topicId
  103. });
  104. $.ajax ({
  105. type : "DELETE",
  106. url : collectData.delete_detail_action_url,
  107. data:data,
  108. contentType: 'application/json;charset=UTF-8',
  109. success: function(result) {
  110. if (result.judge === true)
  111. {
  112. _$this.parent().remove();
  113. }
  114. }
  115. });
  116. });
  117. });
  118. }