简体   繁体   中英

How to call an external restful using $.ajax from within a SharePoint-hosted app (SharePoint Online)

As the title says I'm having trouble calling an external restful service from within SharePoint.

'use strict';

var context = SP.ClientContext.get_current();
var user = context.get_web().get_currentUser();

// This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
$(document).ready(function () {
    getUserName();

    $.ajax({
        dataType: "jsonp",
        url: ' http://ip.jsontest.com/',
        success: function (a, b, c) {
            alert(a);
        },
        error: function (a, b, c) {
        }
    });
});
...

This returns Access Denied. I've been round and round in circles trying to figure out how to make an external call from the browser.

This call doesn't need to be made from within jQuery if there is a better way to do this say using the clientside object model then I'm open to any suggestion.

This is because you are calling http webservice from https (sharepoint online). convert your webservice to https.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM