Javascript jquery-wolframalpha api xml请求
我试图通过Javascript使用WolframAlpha的API。我不明白为什么下面的代码返回空警报。我是jQuery新手,但有人告诉我这是最好的方法Javascript jquery-wolframalpha api xml请求,javascript,jquery,xml,api,wolframalpha,Javascript,Jquery,Xml,Api,Wolframalpha,我试图通过Javascript使用WolframAlpha的API。我不明白为什么下面的代码返回空警报。我是jQuery新手,但有人告诉我这是最好的方法 <html> <head> <script src="jquery-2.1.1.min.js"></script> </head> <body> <script> $.get('http://api.wol
<html>
<head>
<script src="jquery-2.1.1.min.js"></script>
</head>
<body>
<script>
$.get('http://api.wolframalpha.com/v2/query?appid=77P9PL-2QAWEY86WV&input=2x&format=image,plaintext', function(responseText) {
alert(responseText);
});
</script>
</body>
</html>
$.get('http://api.wolframalpha.com/v2/query?appid=77P9PL-2QAWEY86WV&input=2x&format=image,纯文本’,函数(responseText){
警报(responseText);
});
非常感谢您的帮助因此,这是一种称为跨源脚本的安全机制。这里的问题是,您从中调用的服务没有授予您在ajax调用中调用该资源的权限 要阅读更多,请查看 要证明这一点,请看JS小提琴: 您可以在控制台中看到:
(index):1 XMLHttpRequest cannot load http://api.wolframalpha.com/v2/query?appid=77P9PL-2QAWEY86WV&input=2x&format=image,plaintext.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://fiddle.jshell.net' is therefore not allowed access.
这里的另一个答案建议您需要调用此服务器到服务器:您应该使用
console.log(responseText)
并在浏览器的控制台(F12)中查看对象