1

I´m using SP.RequestExecutor.js to make CORS calls in a sharepoint-hosted add-in. executor.executeAsync uses the Microsoft Ajax library, right?

If it's correct, is there a way to set Ajax options, like jQuery.ajax({beforeSend:fn})?

Update note

It's a requirement to use SP.RequestExecutor.js to natively handle digestvalue and to make cross site collections calls.

1 Answer 1

1

In SharePoint Hosted App, You can use jQuery.ajax directly. There is no need to use SP.RequestExecutor.js. SP.RequestExecutor.js does not have any option like beforeSend:fn. In SharePoint Hosted App, execute jQuery.ajax request like following:

jQuery.ajax({
    url: _spPageContextInfo.siteAbsoluteUrl + url,
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
    },
    success: function (data) {
        console.log(data.d.results);
    },
    error: function (error) {
        alert(JSON.stringify(error));
    }
   beforeSend: function(){
     // Handle the beforeSend event
   },
   complete: function(){
     // Handle the complete event
   }
   // ......
 });

If you need to execute request in Host Web, then use _spPageContextInfo.siteAbsoluteUrl. For App Web, use _spPageContextInfo.webAbsoluteUrl

3
  • Hi, thank you for your time. It's a requirement to use SP.RequestExecutor.js to natively handling digestvalue and to make cross site collections calls. Microsoft Ajax has options (OnBegin , OnComplete , OnSuccess, OnFailure) and can be set in a web forms application. So, I'm still waiting for an answer.
    – egidiocs
    Apr 25, 2016 at 9:44
  • Why do u need beforeSend:fn in SP.RequestExecutor.js. Can you share the requirement? The I will try to give a wayaround with SP.RequestExecutor.js Apr 25, 2016 at 10:29
  • The goal was to instantiate a progress bar for a upload process. But I've written some js to create a new XMLHttpRequest instance and added a modXHR.upload.addEventListener('loadstart', fn)
    – egidiocs
    Apr 27, 2016 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.