我有以下这样的json数据:
var myjson = [{"orders":[
{"id":16,"status":"completed","total":"45.00"},
{"id":17,"status":"completed","total":"55.00"}
]}];
但是我需要能够使用这样的URL从远程源获取json数据:
https://example.com/wc-api/v1/orders?consumer_key=ABC&consumer_secret=123
在浏览器中将显示与上面完全相同的JSON数据,但如何在我的javascript中使用它?
有类似的答案问题,但没有一个解决方案似乎有效。对于初学者来说,请理解其中javascript / jQuery经验很少,谢谢! :)
修改
我尝试了这个解决方案:
var page_content;
$.get( "https://example.com/wc-api/v1/orders?consumer_key=ABC&consumer_secret=123", function(data){
page_content = data;
});
我在控制台中收到此错误:
XMLHttpRequest cannot load https://example.com/wc-api/v1/orders?consumer_key=ABC&consumer_secret=123. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
请帮助:(