同步的 XMLHttpRequest 已不推荐使用 , 那怎么实现同步操作呢 ?

$(function () {
  $("img[id^='isshow']").click(function() {
    var $id = $(this).attr('id').replace('isshow', '');
    if ($(this).attr('src').match('yes')) {
      var $isshow = 'yes';
      var $newisshow = 'no';
    } else {
      var $isshow = 'no';
      var $newisshow = 'yes';
    }
    var $data = 0;
    $.ajax({
      type: 'post',
      url: '__URL__/isshowPro',
      // async : false,
      data: {'id':$id, 'isshow':$newisshow},
      success: function (data) {
        $data = data;
      }
    });
    if ($data == 1) {
      $(this).attr('src', function () {
          return $(this).attr('src').replace($isshow, $newisshow);
      });
    }
  })  
})
如果 // async : false , 打开 , 火狐会出现这个警告 :
"主线程中同步的 XMLHttpRequest 已不推荐使用,因其对终端用户的用户体验存在负面影响。更多帮助请见 http://xhr.spec.whatwg.org/"
问 : 如果 async : true , 如何同步地实现这段代码 ?
if ($data == 1) {
      $(this).attr('src', function () {
          return $(this).attr('src').replace($isshow, $newisshow);
      });


hhhzihao2
浏览 16456回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP