Chrome新版本73.0.3683.75的Ajax调用错误?

Céd*_*vin 8 ajax google-chrome google-chrome-extension cors cross-origin-read-blocking

Chrome更新之前,我的代码运行正常。

我向服务器发出ajax调用。我的服务器收到呼叫,将JSON返回给客户端,但是答案始终为空。当我查看Fiddler时,会从服务器得到答案。

在此处输入图片说明

我尝试使用JQuery,也尝试使用xmlhttp调用。总是一样的结果

是否有新的CORS政策规则适用?

有我的xmlHTTP调用

 var xmlhttp = new XMLHttpRequest();   // new HttpRequest instance 
      var theUrl = "URL";
      xmlhttp.open("POST", theUrl);
      xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
      xmlhttp.send('{ "args" :{ "Obj":"my obj"}}');
      xmlhttp.onreadystatechange = function(state,xhh,aaa){
        if (xmlhttp.readyState == XMLHttpRequest.DONE) {
          alert(xmlhttp.responseText);
        }
      }
Run Code Online (Sandbox Code Playgroud)

Ajax调用类似

$.ajax({
        url: "URL",
        data: '{ "args" :{ "Obj":"my obj"}}',
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        type: "POST",
        async: false,       
        error: function (xhr, ajaxOptions, thrownError) {
          if (that.Fail != null) {
            that.Fail();
          }
        },
        success : function(data){

           alert(data);

        }
      })
Run Code Online (Sandbox Code Playgroud)

Han*_*ran 8

I had the same problem after upgrade to Chrome 73. Thanks to @wOxxOm

This is the workaround until now:

  1. Go to chrome://flags
  2. Disabled the Enable network service

一步步


UPDATE:

This is not a bug, according to this announcement: https://www.chromium.org/Home/chromium-security/extension-content-script-fetches

您将需要将“跨域获取”放置到后台脚本而不是内容脚本中。