user1258067
user1258067

Reputation: 11

Google Calculator from Javascript

I'm working on a simple Javascript app, and I need a way to take a string an determine a value by entering it into a calculator. (i.e. if the string is "pi^2 sqrt(3)" you'll get 17.0946563")

Rather than reinventing the wheel, I was hoping there was a way to implement Google's calculator to grab the result. Basically, I want to call http://www.google.com/ig/calculator?hl=en&q= followed by the string, and have Google output the result. The only example I've seen is the one here but it's in PHP. I don't know much PHP, so I was wondering if there was any way to either call the PHP function from within Javascript or implement the function directly with Javascript. Thanks in advance for any advice.

Upvotes: 1

Views: 550

Answers (1)

Jeff
Jeff

Reputation: 14279

You should use a library like jQuery to make an AJAX call to grab and parse the results. You'll need to build up the URL yourself and, if using jQuery, call the $.getJSON method.

Upvotes: 2

Related Questions