0

I'm trying to create a sharepoint app that gets and use json data generated on another web site / web application through an ajax request. Let's say the JSON data I want to get from the other website is a list of some laptop brands.

The sharepoint app / environment is on another server than the website with the laptop brands and the laptop website isn't related to sharepoint in any way. Assume the following:

var laptopUrl = "https://examplewebsite.com/laptopbrands"; // returns a json list with laptop brands
var sharepointWebsite = 'https://totallydifferentwebsite.com/sharepoint';

When navigation to the laptopUrl in the browser it outputs the json data, but when using the code in the sharepoint app no data is returned. I've tried using the following code (and several other jQuery AJAX requests):

$.getJSON( laptopUrl, function( data ) {
    console.log(data); // Empty
});

I've been trying several ways to get the JSON data in the sharepoint app but with no success... I saw an example of a Yahoo weather app that pretty much did what I wanted but when I changed the URL to my own JSON output, the result was empty...

Am I doing something wrong or is what I'm trying to achieve simply not possible?

Thanks in advance,

ilians

1

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.

  • I can't believe I forgot something so silly... Thanks a lot! – Ilians Oct 23 '13 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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