외부 Ajax 요청 / JSON SharePoint App.
-
10-12-2019 - |
문제
AJAX 요청을 통해 다른 웹 사이트 / 웹 응용 프로그램에서 생성 된 JSON 데이터를 가져오고 사용하는 SharePoint 앱을 만들려고합니다. 다른 웹 사이트에서 얻고 싶은 JSON 데이터가 일부 랩탑 브랜드 목록이라고 가정 해 봅시다.
SharePoint App / Environment는 노트북 브랜드와 노트북 웹 사이트가있는 웹 사이트보다 다른 서버에 있으며 어떤 방식 으로든 SharePoint와 관련이 없습니다. 다음을 가정하십시오 :
var laptopUrl = "https://examplewebsite.com/laptopbrands"; // returns a json list with laptop brands
var sharepointWebsite = 'https://totallydifferentwebsite.com/sharepoint';
.
브라우저에서 랩톱 랩톱으로 이동하면 JSON 데이터를 출력하지만 SharePoint 앱에서 코드를 사용할 때는 데이터가 반환되지 않습니다. 다음 코드 (및 여러 다른 JQuery Ajax 요청)를 사용하여 시도했습니다.
$.getJSON( laptopUrl, function( data ) {
console.log(data); // Empty
});
.
SharePoint 앱에서 JSON 데이터를 얻는 여러 가지 방법을 시도해 왔지만 성공하지 못했습니다 ... 나는 야후 날씨 앱 내가 원하는 것을 많이했지만 URL을 내 자신의 JSON 출력으로 변경했을 때 결과는 비어 있었다 ...
나는 뭔가 잘못하거나 내가 가능하지 않으려 고하는 것입니다.
미리 감사드립니다
ilians
해결책
Looks like you need JSONP in this scenario:
JSONP or "JSON with padding" is a communication technique used in JavaScript programs which run in Web browsers. It provides a method to request data from a server in a different domain, something prohibited by typical web browsers because of the same origin policy.
JSONP could be triggered using:
$.getJSON(laptopUrl + "?callback=?", null, function(data)
{
console.log(data);
});
The addition of '?callback=?' will trigger a jsonp request.