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

Created Unassigned: WebUrlFromPageUrl fires twice when not called with webURL param [10145]

$
0
0
According to the documentation the only required param is pageURL, but if called in that way the system makes two calls.

```javascript
$().SPServices({
operation: "WebUrlFromPageUrl",
pageURL: location.protocol + '//' + location.host + location.pathname
})
.then(function (data) {
var $data = $(data);
var result = $data.SPFilterNode("WebUrlFromPageUrlResult").text();
console.log(result.split(location.protocol + '//' + location.host)[1] || '');
});
```

If a webUrl like '/' is added, then only one call occurs.

```javascript
$().SPServices({
webURL: '/',
operation: "WebUrlFromPageUrl",
pageURL: location.protocol + '//' + location.host + location.pathname
})
.then(function (data) {
var $data = $(data);
var result = $data.SPFilterNode("WebUrlFromPageUrlResult").text();
console.log(result.split(location.protocol + '//' + location.host)[1] || '');
});
```
One way to automate this would be to modify the ajaxURL check.

```javascript
// Build the URL for the Ajax call based on which operation we're calling
// If the webURL has been provided, then use it, else use the current site
var ajaxURL = "_vti_bin/" + WSops[opt.operation][0] + ".asmx";
if(opt.webURL.charAt(opt.webURL.length - 1) === SLASH) {
ajaxURL = opt.webURL + ajaxURL;
} else if(opt.webURL.length > 0) {
ajaxURL = opt.webURL + SLASH + ajaxURL;
// set to root if operation equals WebUrlFromPageUrl
} else if (opt.operation === 'WebUrlFromPageUrl') {
ajaxURL = SLASH + ajaxURL;
} else {
ajaxURL = $().SPServices.SPGetCurrentSite() + 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>