Quantcast
Channel: jQuery Library for SharePoint Web Services
Viewing all articles
Browse latest Browse all 6517

Edited Unassigned: SPServices() uses wrong server relative URL on SP2010 [10165]

$
0
0
#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);
}
}
});
```
5. Save and browse the page
6. 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;
```

Viewing all articles
Browse latest Browse all 6517

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>