Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.

Jan 29, 2015 at 7:58 PM
Edited Jan 29, 2015 at 7:59 PM
I'm using SPServices 2014.2 to make some very simple requests to SharePoint lists to grab data. It all works perfectly fine however in recent versions of Firefox and Chrome I see the following warning:

'Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.'

I am using async: true in my requests. I've been trying to resolve this for about 8 hours and am at a total loss. Is there any way I can make sure that SPServices is not making synchronous XMLHttpRequests? Apparently setting async: true is not enough?
Coordinator
Jan 29, 2015 at 8:08 PM
If you're using promises, you should be making asynchronous calls.

Can you show an example of your code?

M.
Jan 29, 2015 at 8:24 PM
Hi, Marc. Here is a sample that produces the following warning in Chrome 40 and Firefox Developer Edition:

"Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/."
function getUserList(finished) {
  var userListPromise =   
     $().SPServices({
      operation: "GetListItems",
      async: true,
      listName: "UserInfo"
    });
  
  userListPromise.done(function() {
    var results = [];

    $(userListPromise.responseXML).SPFilterNode("z:row").each(function() {
      results.push({
        id: $(this).attr("ows_ID"),
        username: $(this).attr("ows_Name"),
        title: $(this).attr("ows_Title")
      });
    });

    finished(results);
  });
}

getUserList(function(u) {
  console.log(u);
});
Coordinator
Jan 29, 2015 at 8:34 PM
It looks like you're doing everything right. You don't need the async: true because that's the default, but otherwise, you're making asynchronous calls.

I hadn't seen that error in Chrome or Firefox, and I'm working with very similar calls right now. I just checked, and I was running Chrome 38, so I updated to 40. Now I'm seeing that warning, too. I'll have to look into it. It seems to just be a warning.

M.
Jan 29, 2015 at 8:37 PM
Thanks Marc for performing a sanity check on my code. I've been digging into this all day. Googling like crazy and reading every thread I could find on this warning. I'll just ignore the warning for now. Thanks!
Coordinator
Jan 29, 2015 at 8:50 PM
BTW, I'm running jQuery 2.1.3 (the latest) when I'm in Chrome 40, so if the issue is in jQuery, it's there in the latest version. I'm just calling their $.ajax function.

M.
Jan 29, 2015 at 8:54 PM
Okay. I'm running jQuery 1.11.2 at the moment.
Coordinator
Jan 29, 2015 at 9:00 PM
Jan 29, 2015 at 9:02 PM
Thanks for the info! I should do the same in my environment.
Jan 29, 2015 at 9:18 PM
Unrelated to SPServices, I actually saw this today as well...

Marc: the warning will continue to be generated for most SPServices calls and I don't believe it is jQuery... I think its being caused by .SPGetCurrentWeb()... if I remember correctly, you do a few different things to see if you can determine what the current WebURL is before attemping to make an API call to get it... that API call in made with async: false - I belive.

(I'm going to have the same issue with my own library - I'm doing the same thing :))


_________
Paul T

Coordinator
Jan 29, 2015 at 9:33 PM
Nice catch, Paul. Yup, it's me then.

Erg. That call is there for backward compatibility with 2007. It ought not to fire if I can determine the current site from JavaScript variables that SharePoint supplies.

M.
Jan 29, 2015 at 10:11 PM
You should be able to put that call into a promise and remove async: false in the process.

Cheers,
Matthew
Jan 30, 2015 at 12:07 AM
SPGetCurrentSite is definitely the culprit. As a quick hack I commented out the ajax call which is using async: false and made the function return my hard coded site address instead and the warning goes away.
Coordinator
Jan 30, 2015 at 2:15 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Jan 30, 2015 at 2:16 PM
Edited Jan 30, 2015 at 4:52 PM
I've put it on my list. Frank, what version of SharePoint are you on?

M.
Jan 30, 2015 at 3:20 PM
I'm on SharePoint 2013
Coordinator
Feb 4, 2015 at 2:21 PM
Edited Feb 4, 2015 at 2:21 PM
Feb 4, 2015 at 3:17 PM
Thanks Marc! I just checked it out. I appreciate your effort in this.