Book Image

PHP Ajax Cookbook

Book Image

PHP Ajax Cookbook

Overview of this book

Table of Contents (16 chapters)
PHP Ajax Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Converting currencies using Ajax and PHP


In this recipe, we will see how to convert currencies using Ajax and PHP. In this example, we will use the API provided by foxrate.org. Forxrate.org has provided the web services in the XML-RPC format. We consumed an XML-RPC web service in this example.

Getting started

Foxrate.org's currency convertor API is located at: http://foxrate.org/rpc/. The method name for the XML-RPC call is foxrate.currencyConvert. The parameters that can be passed to this function are:

  • From currency – This is the code of the currency in which original currency amount is in. Examples can be USD or GBP. The list of currency codes of currencies can be found here: http://en.wikipedia.org/wiki/ISO_4217.

  • Targetted currency – This is the currency code of the targeted currency to which the amount needs to be converted.

  • Amount – The third parameter to the method call is the amount that needs to be converted from the original currency to the targeted currency.

Now, let's look at what the...