Answer the question
In order to leave comments, you need to log in
How to connect to Gumroad API using AJAX?
Friends, I'm completely desperate: I can't figure out how to write a JS script correctly to get data from the Gumroad API.
The API docs say they respond with JSON, however I can't use a JSON request as this results in an error
Cross-Origin Request Blocked:
The Same Origin Policy disallows reading the remote resource
at https://api.gumroad.com/v2/products.
(Reason: CORS header 'Access-Control-Allow-Origin' missing).
“SyntaxError: missing ; before statement",
"Refused to execute script from 'my request' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled."
Вариант 1
jQuery.ajax({
dataType: 'jsonp',
url: 'https://api.gumroad.com/v2/products',
data: {
'access_token': '676234257caeb63ca7683c39d14e0091387a1a36af0c2135f989d0fd84ffc0c5'
},
success: function(data){
console.log(data);
},
error: function(d){
console.log(d);
}
});
Вариант 2
jQuery(document).ready(function() {
var url = 'https://api.gumroad.com/v2/products/';
url += '?method=getQuote';
url += '&format=jsonp';
url += '&lang=en&';
url += 'jsonp=myJsonMethod';
url += '&?callback=?';
url += '&access_token=676234257caeb63ca7683c39d14e0091387a1a36af0c2135f989d0fd84ffc0c5';
jQuery.getJSON(url);
});
function myJsonMethod(response){
console.log (response);
}
Вариант 3
function jsonp(url) {
var head = document.head;
var script = document.createElement("script");
script.setAttribute("src", url);
head.appendChild(script);
head.removeChild(script);
}
jsonp("https://api.gumroad.com/v2/products?callback=jsonpCallback&access_token=676234257caeb63ca7683c39d14e0091387a1a36af0c2135f989d0fd84ffc0c5");
function jsonpCallback(data) {
document.getElementById("response").textContent = JSON.stringify(data);
}
https://api.gumroad.com/v2/products?callback=jQuery112409655243732650752_1495261525390&access_token=676234257caeb63ca7683c39d14e0091387a1a36af0c2135f989d0fd84ffc0c5&_=1495261525391
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question