sunny123456

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

$.post 和 $.get 设置同步和异步请求

由于$.post() 和 $.get() 默认是 异步请求,如果需要同步请求,则可以进行如下使用:
在$.post()前把ajax设置为同步:$.ajaxSettings.async = false;
在$.post()后把ajax改回为异步:$.ajaxSettings.async = true;

 $.ajaxSettings.async = false;
        $.post(url, {id:id}, function(res) {
          if (res.code == 0) {
              alert(res.message);
              e.stopPropagation();
              e.preventDefault();
              $(this).attr('href','jacascript::void(0)');
          }
        },

 

https://blog.51cto.com/u_15230485/2822912
posted on 2022-08-26 12:23  sunny123456  阅读(1057)  评论(0编辑  收藏  举报