water_add.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. $(function () {
  2. $("#form-content-add").validate({
  3. rules:{
  4. name:{
  5. required:true,
  6. minlength:1,
  7. maxlength:45,
  8. remote: {
  9. url: pagePath+"/build/water/isExist",
  10. type: "get",
  11. data: {
  12. name: function () {
  13. return $("#name").val();
  14. }
  15. }
  16. }
  17. },
  18. remarks: {
  19. maxlength: 45,
  20. }
  21. },
  22. messages : {
  23. name : {
  24. remote: "该水表名已存在!"
  25. },
  26. remark: {
  27. maxlength: "备注长度不能超过45个字符!"
  28. }
  29. },
  30. onkeyup:false,
  31. focusCleanup:true,
  32. success:"valid",
  33. submitHandler:function(form){
  34. $(form).ajaxSubmit({
  35. type: 'post',
  36. url: pagePath+"/build/water/saveWater",
  37. dataType:"json",
  38. success: function(result){
  39. if (result.success) {
  40. smileMessage(result.message);
  41. setTimeClose();
  42. } else {
  43. errorMessage(result.message);
  44. }
  45. }
  46. });
  47. return false; // 非常重要,如果是false,则表明是不跳转,在本页上处理,也就是ajax,如果是非false,则传统的form跳转。
  48. }
  49. });
  50. });