0

I can't seem to figure out how to access the XML data from the Wolfram API. This page is a REST-style API, although I'm still learning what that means.

A sample query page is here: http://api.wolframalpha.com/v2/query?input=pi&appid=P4R357-G2X7K6U2J5

How would I use AJAX to access and use the XML data from this page?

I copied and modified this code, which worked for a json page. However, I don't know how to get the data from the Wolfram API XML page. With this code, I believe that seeing a message of "Success" means that I have successfully gotten the url.

I will worry about the formatting after I figure out how to just get the data.

I am very new to this, so any help would be greatly appreciated. Thanks a lot!

$(document).ready(function() {
    $.ajax({
      type: "GET",
      url: "http://api.wolframalpha.com/v2/query?input=pi&appid=P4R357-G2X7K6U2J5",
      dataType: "xml",
      success: function(xml){
        document.write("Success");
      }

    }).then(function(data) {
      document.write("Success");
    });
});
Lumi Lu
  • 3,289
  • 1
  • 11
  • 21

1 Answers1

0

You shouldn't be able to make cross domain Ajax calls with dataType 'xml'. Hence, success event is never triggered. Only 'jsonp' dataType will work for cross domain calls.

dhunju
  • 71
  • 3
  • Yes, you can may be do the API call to wolfram in back-end on your server with something like PHP to make HTTP GET call and get response xml. – dhunju Jan 06 '15 at 06:14