2

Closed

SPServices() uses wrong server relative URL on SP2010

description

Description:

Calling SPServices() from a page located at root website Pages library (e.g. http://<server>/Pages/default.aspx) to access a list at same level (e.g. http://<server>/Lists/MyList) might try to access an incorrect URL.

Steps to reproduce:

  1. Create a Publishing site
  2. Create a page in /Pages library (e.g. default.aspx)
  3. Create a custom list in /Lists (e.g. MyList)
  4. Use following code in default.aspx from a Content Editor Web Part pointing to existing file with the code (SP2010):
$().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "MyList",
    CAMLQuery: "",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
    completefunc: function(xData, status)
    {
        if (status == "error")
        {
            console.log("Error: " + xData.statusText);
        }
        else
        {
            var rows = $(xData.responseXML).SPFilterNode("z:row");

            console.log("Rows retrieved: " + rows.length);
        }
    }
});
  1. Save and browse the page
  2. Console will display the message "Error: Transport error" as jQuery AJAX request tries to access //_vti_bin/Lists.aspx instead of /_vti_bin/Lists.aspx (notice the double-slash at the beginning).

Workaround:

Modify jquery.SPServices-2013.01.js file at line 428 from:
ajaxURL = $().SPServices.SPGetCurrentSite() + SLASH + ajaxURL;
so it runs following code:
var currentSite = $().SPServices.SPGetCurrentSite();
ajaxURL = currentSite + (currentSite !== SLASH ? SLASH : "") + ajaxURL;
Closed Dec 28, 2013 at 6:49 PM by sympmarc
Released in 2013.02

comments

sympmarc wrote Oct 8, 2013 at 8:37 PM

Implemented in 2013.02ALPHA3

ptavares wrote Oct 15, 2013 at 11:22 PM

Marc,
I think I just got bit by this (was running ALPHA2 to test the GetItemChangesSinceToken issue)... When you get a chance, can you post 2013.02ALPHA3 ?

Paul.

sympmarc wrote Oct 16, 2013 at 12:38 AM

Done!

ptavares wrote Oct 16, 2013 at 1:23 AM

Wow. Now that was quick. Thanks Marc.