Showing posts with label YQL. Show all posts
Showing posts with label YQL. Show all posts

Thursday, 25 April 2013

Use Google Currency Converter API in JQuery

        function buildQuery(amount, from, to) {
            var str = "http://www.google.com/ig/calculator?hl=en&q=" + amount + "" + from + "%3D%3F" + to + "";
            return "select * from json where url ='" + str + "' ";
        }

        $.ajax({
            url: 'http://query.yahooapis.com/v1/public/yql',
            data: {
                q: buildQuery("100","KWD","INR"),
                format: "json"
            },
            dataType: "jsonp",
            success: function (data) {
                alert(data.query.results.json.lhs + "=" + data.query.results.json.rhs);
            },
            error: function (data) {
                consol.log(data);
            }
      });
Just change buildQuery("100","KWD","INR") parameters.

Live Demo



Saturday, 20 April 2013

Getting cross domain JSON Data by ajax request

Their is two way to get data from other domain.

1. By using YQL Yahoo Service. Here is example :-

function buildQuery(term) {
    return "select * from json where url = 'http://airportcode.riobard.com/search?fmt=JSON&q=" + term + "'";
}

$.ajax({
        url: 'http://query.yahooapis.com/v1/public/yql',
        data: {
            q: buildQuery(YourURL),
            format: "json"
        },
        dataType: "jsonp",
        success: function(data) {
            alert(JSON.stringify(data));
        },
        error: function (data) {
            consol.log(data);
        }
});


2. By using $.getJSON Here is example-


$.getJSON("http://kalpa.freeoda.com/news/news_feed.php?callback=?", null, function (data) {
            alert(JSON.stringify(data));
});