project_edit.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. $(function () {
  2. $("#form-project-edit").validate({
  3. rules: {
  4. project_name: {
  5. required: true,
  6. minlength: 1,
  7. maxlength: 60,
  8. remote: {
  9. url: pagePath + "/project/isExistProjectName",
  10. type: "get",
  11. data: {
  12. name: function () {
  13. return $.trim($("#project_name").val());
  14. },
  15. id: function () {
  16. return $.trim($("#project_id").val());
  17. },
  18. type: function () {
  19. return $.trim($("#project_type").val());
  20. }
  21. }
  22. }
  23. }
  24. },
  25. messages: {
  26. project_name: {
  27. remote: "该项目名称已存在!"
  28. }
  29. },
  30. onkeyup: false,
  31. focusCleanup: true,
  32. focusInvalid:false,
  33. success: "valid",
  34. submitHandler: function (form) {
  35. // $(form).find(":submit").attr("disabled", true);
  36. $(form).ajaxSubmit({
  37. type: 'post',
  38. url: pagePath + "/project/save",
  39. dataType: "json",
  40. success: function (data) {
  41. if (data.success) {
  42. succeedMessage(data.message);
  43. setTimeClose();
  44. } else {
  45. // $(form).find(":submit").attr("disabled", false);
  46. errorMessage(data.message);
  47. }
  48. },
  49. error: function () {
  50. errorMessage('系统错误!');
  51. }
  52. });
  53. return false; // 非常重要,如果是false,则表明是不跳转,在本页上处理,也就是ajax,如果是非false,则传统的form跳转。
  54. }
  55. });
  56. });