Ajax beforeSend和complete 方法

举报
lxw1844912514 发表于 2022/03/27 02:24:23 2022/03/27
【摘要】 http://blog.csdn.net/chenjianandiyi/article/details/52274591.ajax({ beforeSend: function(){ // Handle the beforeSend event }, complete: function(){ /...

   
  1. http://blog.csdn.net/chenjianandiyi/article/details/52274591
  2. .ajax({
  3. beforeSend: function(){
  4. // Handle the beforeSend event
  5. },
  6. complete: function(){
  7. // Handle the complete event
  8. }
  9. // ......
  10. });
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

其中的$.ajax请求中有一个beforeSend方法,用于在向服务器发送请求前执行一些动作。

complete 方法执行完后调用

用途

防止重复数据


   
  1. // 提交表单数据到后台处理
  2. $.ajax({
  3. type: "post",
  4. data: studentInfo,
  5. contentType: "application/json",
  6. url: "/Home/Submit",
  7. beforeSend: function () {
  8. // 禁用按钮防止重复提交
  9. $("#submit").attr({ disabled: "disabled" });
  10. },
  11. success: function (data) {
  12. if (data == "Success") {
  13. //清空输入框
  14. clearBox();
  15. }
  16. },
  17. complete: function () {
  18. $("#submit").removeAttr("disabled");
  19. },
  20. error: function (data) {
  21. console.info("error: " + data.responseText);
  22. }
  23. });
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

模拟Toast效果


   
  1. $.ajax({
  2. type: "post",
  3. contentType: "application/json",
  4. url: "/Home/GetList",
  5. beforeSend: function () {
  6. $("loading").show();
  7. },
  8. success: function (data) {
  9. if (data == "Success") {
  10. // ...
  11. }
  12. },
  13. complete: function () {
  14. $("loading").hide();
  15. },
  16. error: function (data) {
  17. console.info("error: " + data.responseText);
  18. }
  19. });

文章来源: blog.csdn.net,作者:lxw1844912514,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/lxw1844912514/article/details/100029168

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。