Synchronous XMLHttpRequest Warning with SPServices and Recent Browsers

keep-calm-and-learn-javascript
Image source

If you’re working in the latest versions of Chrome (~40+) – and maybe Firefox – and you use SPServices, you may start to see an 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/.

Vigilant SPServices user frankhale reported this to me the other day in the SPServices discussions on Codeplex, which is – at least at the moment – the best place to get help with SPServices. You can also add an issue on Github (sympmarc / SPServices) if that’s your fancy.

The warning is thrown in jQuery, not SPServices, but it’s an SPServices issue.

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

First off, it’s a warning, not an error. Your code will continue to work in the near term, at least.

Because of some backward compatibility concerns, I’ve left a few synchronous calls internally to SPServices in place. Those calls are what are causing the warning. In particular, it is most likely that the warning is being thrown for you because of a synchronous call on the $().SPServices.SPGetCurrentSite function. The reason for this is that early in the SharePoint 2007 days it was difficult to determine the current site without a call to the Webs.WebUrlFromPageUrl operation. Unfortunately, it seems that I’m making that call in SharePoint 2010 and 2013, even though the current site is available in JavaScript variables.

So, the bottom line is: “Carry on.” I’ll get a fix into the next release of SPServices for this. In the meantime you should be fine.

Similar Posts

7 Comments

  1. Hi Marc,

    I am using $().SPServices.SPAutocomplete which pulls data from other list and based on selected value I am also auto-populating data for other columns using $().SPServices. The first service is working without any issue but auto-populating data for other columns is not working. I am using jquery.SPServices-2014.01.js in SharePoint 2013 and using IE11. Could you please help me here.

      1. Marc:

        Please find my piece of code below.

        $().SPServices.SPAutocomplete({
        WebURL: "SITE URL",
        sourceList: "LIST NAME",
        sourceColumn: "COLUMN NAME1",
        columnName: "COLUMN NAME2",
        filterType: "Contains",
        numChars: 3,
        ignoreCase: true,
        slideDownSpeed: 100,
        debug: true
        });
         
        
        var selectedAutoText="";
        
        $("#SPAutocomplete_undefined").click(function()		//id of the dropdown list(ul tag) using developer tools
        			{
        			$(this).children().each(function()		// loop through all li under ul
        				{
        				if($(this).css("background-color") == "#3399ff")
        				{ 
        						
        					selectedAutoText=$(this).html();		// gets the selected value				
        		       var query =''+selectedAutoText+'';
         
        $().SPServices({
                    operation: "GetListItems",
                    webURL:"SITE URL",
                    async: false,
                    listName: "LIST NAME",
                    CAMLQuery: query,
                    CAMLViewFields: "",
                    completefunc: function (xData, Status) {
                       $(xData.responseXML).SPFilterNode("z:row").each(function () {
                          	var Col1 = $(this).attr("Column Internal Name");
        			var Col2 = $(this).attr("Column Internal Name");
        
        		});
        	}
        });
        
        }
        });
        
        });
        

        $().SPServices is not hitting here. But the same code is working well with SP2010. All columns are Single Line of Textboxes. I also tried 2014.02 but its not working.

        Let me know if you need more info.

Leave a Reply to Akash Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.