How to get JSON data from a remote service in a SharePoint 2013 app?
-
10-12-2019 - |
Question
I am working on an App for SharePoint 2013 that is SharePoint-hosted and I can't get data from a remote web service using a jQuery.ajax call. The only two ways to get remote data documented by Microsoft are: using a web proxy call or a custom proxy page.
Are these methods the only ones that you can use or is there something else available? I am looking for something that is similar with the jQuery.ajax call.
Solution
Here is a method to accomplish this: from the JavaScript page code use the jQuery.ajax function with the argument "dataType" set to "jsonp" and call the web service that supports jsonp requests and that returns a json result back.
You can find more details about a .NET specific implementation of a web service and the call code here: Rick Strahl - Creating a JSONP Formatter for ASP.NET Web API. You can get data from any web service that supports jsonp calls: it can be a node.js or a rails service.