Ajax call bug with Chrome new version 73.0.3683.75?

别说谁变了你拦得住时间么 提交于 2019-11-26 09:59:08

问题


My code was working fine before the Chrome update.

I make an ajax call to my server. My server receives the call, returns JSON to the client, but the answer is always empty. When I look in Fiddler I get an answer from the server.

I try with JQuery, and I also try with an xmlhttp call. Always the same result

Did new CORS policy rules apply...?

There is my xmlHTTP call

 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);
        }
      }

The ajax call is similar

$.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);

        }
      })

回答1:


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

You will need to put the Cross-Origin Fetches to the background script instead of the content script.



来源:https://stackoverflow.com/questions/55153888/ajax-call-bug-with-chrome-new-version-73-0-3683-75

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!