Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax call bug with Chrome new version 73.0.3683.75?

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.

enter image description here

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

        }
      })
like image 654
Cédric Boivin Avatar asked Mar 14 '19 02:03

Cédric Boivin


People also ask

Does AJAX work in Chrome?

New! Save questions or answers and organize your favorite content. Learn more.

How do I stop multiple AJAX calls from repeated clicks?

}); If isLoading is false, the AJAX call starts, and we immediately change its value to true. Once the AJAX response is received, we turn the value of that variable back to false, so that we can stop ignoring new clicks.

What causes AJAX errors?

Many pages send AJAX requests to a server. Because this relies on the cooperation of the server and the network between the client and the server, you can expect these AJAX errors: Your JavaScript program receives an error response instead of data; Your program has to wait too long for the response.

What is the replacement of AJAX?

Ajax is gradually being replaced by functions within JavaScript frameworks and the official Fetch API Standard.


1 Answers

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

Step by step


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.

like image 131
Han Tran Avatar answered Sep 22 '22 19:09

Han Tran