jquery - wolframalpha api xml request

558 views Asked by At

I am trying to use WolframAlpha's API through Javascript. I don't understand why the following code returns me an empty alert. I'm new at jQuery, but I was told it was the best method to use right here.

<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>

Thank you very much for your help

1

There are 1 answers

0
Dave Walker On BEST ANSWER

so this is suffering from a security mechanism called Cross Origin Scripting. The issue here is that the service you are calling from has not given permission for you to call that resource in an ajax call.

To read more look at http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

To prove this is happening look at the JS Fiddle : http://jsfiddle.net/dgohczvf/1/

You can see in the console:

(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.

Another answer here suggested that you need to call this server to server: Wolfram API javascript cross origin sharing issue