Use return value from Ajax call
29/11/2017 12:19
var myFunctions =
{
checkEditRightsForFolder: function (destUrl, destWebUrl, destWebId) {
var postData = JSON.stringify({ destUrl: destUrl, destWebUrl: destWebUrl, destWebId: destWebId });
var url = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/myfolder/MyAppPage.aspx/MyWebMethod";
var _deferred = $.Deferred();
jQuery.ajax({
url: url,
type: 'POST',
data: postData,
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val(),
"Accept-Language": _spPageContextInfo.currentUICultureName
},
success: function (data) {
var response = jQuery.parseJSON(data.d);
//MyWebMethod returns edit rights message what we want to display
_deferred.resolve(response);
},
error: function (err) {
_deferred.reject(err.statusText);
}
});
return _deferred;
}
}
call method and process result
myFunctions.checkEditRightsForFolder(selectedFolderUrl, siteUrl, webId).then(function (edithRightsMessage) {
if (edithRightsMessage == '') {
//do something
}
else {
}
});var myFunctions =
{
checkEditRightsForFolder: function (destUrl, destWebUrl, destWebId) {
var postData = JSON.stringify({ destUrl: destUrl, destWebUrl: destWebUrl, destWebId: destWebId });
var url = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/myfolder/MyAppPage.aspx/MyWebMethod";
var _deferred = $.Deferred();
jQuery.ajax({
url: url,
type: 'POST',
data: postData,
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
},
success: function (data) {
var response = jQuery.parseJSON(data.d);
//MyWebMethod returns edit rights message what we want to display
_deferred.resolve(response);
},
error: function (err) {
_deferred.reject(err.statusText);
}
});
return _deferred;
}
}
call method and process result
myFunctions.checkEditRightsForFolder(selectedFolderUrl, siteUrl, webId).then(function (edithRightsMessage) {
if (edithRightsMessage == '') {
//do something
}
else {
}
});