Making a JSON request using YQL and MooTools

As a novice in JavaScript and web technologies, I am currently working with JSON files from another domain. I am attempting to make a cross-domain request by using YQL as a proxy. Although I acknowledge that my code may not be the most elegant at this point, I am open to improving it with your assistance.

Here is the current state of my code:

function GetUrl() {
    var link = "http://m.airpim.com/json/public/search?q=variabile&k=&e=1",
        name = document.id('s').get('value') || '*';

    return link.replace("variabile", name);
}

function Ricerca() {
    var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from json where url="' + GetUrl() + '"') + '&format=json&diagnostics=false&callback=';
    return yql;
}

function LavoroJson() {
    var ciao = new Request.JSONP({
        url: Ricerca(),
        onComplete: function(data) {
            // Log the result to console for inspection
            alert(ciao.toSource());
        }
    }).send();
}

Despite my intention to make the JSON request using YQL, it seems that the current implementation is not functioning properly. What steps can I take to address this issue?

Answer №1

If you want to customize the Request.JSONP class, you can create a new class called Request.YQLJSON.

Request.YQLJSON = new Class({
    // This class retrieves basic information such as country and latitude data
    Extends: Request.JSONP,

    options: {
        log: !true,
        url: "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3D%22{location}%22&format=json"
    },

    initialize: function(location, options) {
        this.parent(options);
        if (!location)
            return;

        this.options.url = this.options.url.substitute({location: encodeURIComponent(location)});
    },

    success: function(data, script) {
        this.parent(data, script);
    }
});

You can also create your own DSL implementation for specific airpim details:

Request.airpim = new Class({

    Extends: Request.YQLJSON,

    options: {
        suburl: "http://m.airpim.com/json/public/search?q={search}&k=&e=1"
    },

    initialize: function(query, options) {
        this.parent(this.options.suburl.substitute({
            search: encodeURIComponent(query)
        }), options);
    }

});

To use this custom request, follow these steps:

new Request.airpim("*", {
    onSuccess: function(data) {
        console.log(data.query.results.json);
    }
}).send();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieving the present precipitation amount from a Java Script API

I'm having some issues with extracting information from this list because I don't have much experience with JavaScript and APIs. The API I'm working with provides data for the current hour, but I'm struggling to retrieve that specific v ...

Leveraging the power of a three.js canvas in conjunction with Custombox

I am currently using three.js to generate a 360 panorama on my webpage. I have a collection of thumbnails displayed on the page, and when a thumbnail is clicked, two actions take place. The correct texture is swapped into the panorama canvas (which is fu ...

How can I deactivate the main color of the FormLabel when the focus is on the radio button group?

Is there a way to change the color of FormLabel to black instead of the primary color when the radio button group is focused? https://i.sstatic.net/h3hML.png const styles = { formLabel: { color: "#000" }, formLabelFocused: { color: "#000" ...

Exploring the world of WebSockets and Socket.io

Recently many online games, like , have started using WebSockets to create real-time MMORPGs. I'm curious about how to develop a node.js program that can manage connections from browsers using WebSockets. Here is an example of browser code: <!DOC ...

Turning the Three.js camera to the left and right side

My goal in Three.js is to create an orbiting camera that can be rotated around the x and y axes. I have implemented two functions to achieve this: function rotateX(rot) { var x = camera.position.x, y = camera.position.y, ...

Babel is failing to transpile the Modal component from material-ui-next to ES5

Issue with Babel transpiling Modal component from material-ui-next Here is my .babelrc configuration: { "presets": ["es2015", "react", "stage-1", "stage-2", "stage-3"] } This is the webpack-config.js setup: var webpack = require('webpack'); ...

Enhance Laravel 5 by integrating browserify into the Elixir build process

My workflow for transforming coffee to js using browserify, browserify-shim, and coffeeify looks like this: I work with two main files: app.coffee and _app.coffee, designated for frontend and backend respectively. These files are located in resources/coff ...

Navigating to a specific route using React-Router through the root component

How can I implement a search functionality in my application where the navbar's textbox is used to navigate to the search results page no matter the route, such as / or /listing/foo? The issue I am facing is that the conventional method of programmati ...

Inconsistency in @nuxtjs/i18n locales after refreshing the page

I am currently working on an application where I am implementing language management, but I have encountered a difficulty. I am using the latest version of @nuxtjs/i18n. Changing the language successfully updates the URL and labels, yet upon refreshing the ...

What measures can be taken to safeguard my web app from unauthorized devices attempting to connect?

I am looking for a way to restrict access to a webapp so that only authorized users can connect from approved computers or mobile devices. If a user enters the correct username and password, access will be granted only if they are using a device approved b ...

Having trouble printing webpages? Need a useful tutorial on how to print web pages created using jQuery UI, jqGrid, and Zend?

I have been tasked with printing web pages of a website that utilize jqgrid, Jquery calendar, various Jquery UI components, and background images. The server side is built with Zend Framework. Although I lack experience in web page printing, this has beco ...

Internet Explorer terminates AJAX requests

When I send a request to the server using Ajax and JQuery, it returns more than 2000 records (approximately 16,000 records). In Google Chrome, the call is executed although it takes about 40 seconds. However, in Internet Explorer 11, the execution gets ca ...

Design a Custom Component in React with Generic Capabilities

Here I have a question related to creating a CustomView component in react-native. While the code is written using typescript, the concepts discussed can also be applied to react. In my current implementation, I have defined styles for the CustomView and ...

Building custom relationship resources in Laravel API

I have a complex query that retrieves user data from multiple related tables. While I would like to handle the JsonResource format, I am struggling to generate it as seamlessly as with the regular query. Method index: public function index() { $users ...

Next.js encountering page not found error due to broken link URL

Currently, I am working on implementing a login system in next.js. In the login page, I have included a Link to the Register page using the Link href attribute. However, every time I click on that link, it displays a message saying "404 page not found." Al ...

Extract the value of a key from a particular object in a JSON array using JavaScript

I have a JSON structure that looks like this: { map: [ {"key1":"valueA1", "key2":"valueA2", "key3":"valueA3"}, {"key1":"valueB1", "key2":"valueB2", "key3":"valueB3"}, {"key1":"valueC1", "key2":"valueC2", "key3":"valueC3"}, .... an ...

Transferring information about service events to a controller in Angular

I am facing an issue with some audio elements in my service that listen for the "ended" event. I am looking for a way to pass this message to an angular controller. Currently, my service code looks like this: Audio.addEventListener "ended", (-> ...

How can the Header of a get-request for an npm module be modified?

Currently, I am utilizing an npm module to perform an API request: const api_req = require('my-npm-module-that-makes-an-api-request'); However, I am seeking a way to modify the user-agent used for requests generated internally by the npm module ...

Tips for avoiding visual disturbance during page loading in AngularJS

I have developed a basic application using AngularJS. Upon loading the page, I briefly see the initial screen as shown below: However, once the page fully loads, the content is properly displayed and styled: How can I prevent the AngularJS code from flas ...

What is the best way to handle a specific submit button using jQuery/Ajax?

I created a web page with 4 submit buttons that all call the same PHP page process.php using jQuery/Ajax. I trigger this PHP page using the onClick event as shown below: <div class="col-md-12"> <input type="hidden" name="_token" value="<?p ...