question_js.html 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <script type=text/javascript>
  2. function preview(){
  3. $.post("{{ url_for('question.preview') }}", {
  4. content: $("#content").val(),
  5. choice: $("#choice").val()
  6. }, function(data) {
  7. $("#showPreview").html(data);
  8. });
  9. }
  10. $(document).ready(function(){
  11. $('button#ajax').click(function() {
  12. $.ajax ({
  13. type : "POST",
  14. url : "{{ request.path }}",
  15. data:JSON.stringify({
  16. title: $('#title').val(),
  17. content: $('#content').val(),
  18. tags: $('#tags').val(),
  19. choice: $('#choice').val()
  20. }),
  21. contentType: 'application/json;charset=UTF-8',
  22. success: function(result) {
  23. if (result.judge == true)
  24. {
  25. window.location = '{{ url_for('board.board') }}';
  26. }
  27. else
  28. {
  29. $("#showerror").show();
  30. $("#error").text(result.error);
  31. }
  32. }
  33. });
  34. });
  35. });
  36. </script>