Retrieving Pebble's exchange rate data via JSON API

As I work on developing a basic watchface for Pebble, I'm encountering a JavaScript error that's giving me some trouble.

The data is being sourced from

Here's a snippet of the code:

function HTTPGET(url) {
    var req = new XMLHttpRequest();
    req.open("GET", url, false);
    req.send(null);
    return req.responseText;
}
var getWeather = function() {
    var lhs1 = "usd";
    var rhs1 = "jpy";
    var url1 = "rate-exchange.appspot.com/currency?from=" + lhs1 + "&to=" + rhs1
    console.log(url1);
    var response1 = HTTPGET(url1);
    var json1 = JSON.parse(response1);

and so forth. The issue arises with the following error message:

[PHONE] pebble-app.js:?: JS: where.is.spot: rate-exchange.appspot.com/currency?from=usd&to=jpy
[PHONE] pebble-app.js:?: Error: where.is.spot: Invalid URL at line 4 in pebble-js-app.js

This problem occurs at line 4 specifically: req.send(null);

Any thoughts on what might be causing this error? Everything seems fine with the data feed.

Answer №1

It is important to remember that your URL must always begin with http://:

For instance, transform:

var link1 = "rate-exchange.appspot.com/currency?from=" + item1 + "&to=" + selection1

to:

var link1 = "http://rate-exchange.appspot.com/currency?from=" + item1 + "&to=" + selection1

Answer №2

Choose the following option instead:

req.send();

Answer №3

For those interested in experimenting with jQuery:

let retrieveExchangeRate = function() {

  let apiEndpoint = 'http://rate-exchange.appspot.com/currency?from=usd&to=jpy'

  $.getJSON( apiEndpoint, function( result ) {
   console.log(result);
  });

};

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

Is there a way to fix the close button on the menu so that it works more than once?

I have developed a JavaScript-powered navbar, but I am facing an issue with the closing button. It seems to work only once. If I try to open and close the menu repeatedly, the closing button stops working. I suspect there might be an error in my code, but ...

Setting the default value of a multi-select dropdown in AngularJS from the controller

Currently, I have implemented AngularJS multi select drop down functionality on my website. The code for this can be found at the following source: MultiSelectDropDown In my HTML page, I have included the same drop down twice and I want to customize the ...

Angular module now equipped with web worker for independent operation

My goal is to create a standalone AngularJS module that utilizes web workers for handling heavier processing tasks. This module will be integrated into an Angular web application that I am currently developing, as well as potentially other projects. I env ...

Angular Material Password Confirmation

Currently, I am working on implementing user authentication using Angular Material. Specifically, I am focusing on displaying the appropriate error message when the confirmed password does not match the initially entered password. Below is the snippet of ...

Adding a Javascript function dynamically and calling it in real-time

After a click event on the page, I use ajax to retrieve a block of html and script. Although I can successfully append the script element to the head element, WebKit based browsers are not recognizing it as a script (meaning I am unable to call a function ...

Converting an array to JSON for a tree structure in PHP

I am struggling to convert an array directory (folders and files) into JSON following a specific structure. I have tried researching and attempting different methods, but nothing seems to work. The last code I wrote for this task is as follows: <?php $ ...

I must condense an array

How can I flatten an array of objects: var mylist = [{ THEMEID: 1, TITLE: "myTheme1", PARENTID: 0, children: [{ ITEMID: 1, NAME: "myItem1", THEMEID: 1, PARENTID: 1, TITLE: "myItem1" }, ...

Combining an array into another array using the same key in JavaScript

My goal is to merge the array itself and transform it into a more meaningful array array = [ {item: 'pen', madeIn: 'US', color: 'blue'}, {item: 'pen', madeIn: 'US', color: 'white'}, {item: ' ...

Generating multiple JSON files through a scheduled task using a PHP script

It's quite important for me to mention that while I have some experience with JavaScript, I don't really know how to write PHP. Recently, I created a PHP script that scrapes data from a website and writes it to 22 different JSON files. When I ac ...

Glistening: sending reactiveValues to conditionalPanel

Is it possible to pass a reactiveValues to the condition of a conditionalPanel? If so, what is the correct method? Below is my attempt in the UI.R file for the conditionalPanel: conditionalPanel(condition = "values.cond == 0", etc. I have defined values ...

Discover the steps to eliminate an element's attribute with the help of mutationObserver and mutationrecord

In an effort to remove attributes added by a 3rd party library from my webapp at runtime, I have been using the code provided below: document.addEventListener('DOMNodeInserted', () => { const elements = document.querySelectorAll('[aria- ...

How can the value attribute be obtained from the click class?

$(document).on('click','.edit', function(){ var appid = $(this).getAttribute('value'); I am trying to figure out how to save the value of the "value" attribute for an image with the edit class. Can anyone help me with thi ...

Guide to inserting .json data into a .js file

Currently, I have an HTML5 banner designed using Flash CC. However, the platform in which I am showcasing this ad does not support JSON files. I am looking for a way to transfer the information from the JSON file into either my .html or .js file so that ...

Trigger a click event upon page load using jQuery or JavaScript

I tried searching for this functionality on a different website, but it didn't work on my site. Can you help me figure out how to trigger a click event on page load? On one of my pages, a popup box appears when I click on a "project" link. Here is th ...

Struggling to make Tumblr Javascript function properly

I have integrated the following code snippet: <script type="text/javascript" src="http://underlineent.tumblr.com/api/read/json"> </script> Unfortunately, my Tumblr blog is not appearing on this site. Can anyone provide assistance? The provid ...

Creating an array in Angular is done by using the syntax []

I encountered an error and I'm not sure how to fix it. Can someone assist me? The error message reads: "Type '{ animal:[{ id : 1,name: "Elephant"},{id : 2, name: "Horse"} []; }' is not assignable to type 'string[]'. Property & ...

What is the mechanism behind making a Promise appear synchronous when using a Proxy in JavaScript?

const handler: ProxyHandler<any> = { get: (target: Promise<any>, prop: string, receiver: any) => { return target.then((o) => { return o[prop].apply(o); }); }, }; return new Proxy(obj, handler) ...

Designing an opening interface for an HTML5 Canvas gaming experience?

It's common knowledge that the HTML5 Canvas element interfaces seamlessly with the incredibly efficient Javascript Engines found in Firefox, Safari and Chrome. Lately, I've been delving into game development using Javascript and the Canvas, and ...

Regular expressions or regex can be used to match the initial letter or letters of various words

Struggling with regex? After searching for an hour, the best solution found was this one. Still unable to crack it though... Here's what I need: Have a JS array that needs to be filtered. The array looks like: [ 'Gurken halbiert 2kg', &a ...

An easy way to insert a horizontal line between your text

Currently, I have two text responses from my backend and I'm considering how to format them as shown in the design below. Is it possible to automatically add a horizontal line to separate the texts if there are two or more broadcasts instead of displa ...