mine.js 2.8 KB

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