Question

I am trying to write a simple watchface for Pebble and am coming up against this javascript error.

I am pulling the info from http://rate-exchange.appspot.com/currency?from=usd&to=jpy

The code looks like:

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);

etc and it goes on but you get the idea.

I get this

[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

which is failing at line 4 here: req.send(null);

Any idea what is causing this error? There doesnt seem to be anything wrong with the feed.

Was it helpful?

Solution

Your url should start with http://:

Change:

var url1 = "rate-exchange.appspot.com/currency?from=" + lhs1 + "&to=" + rhs1

into:

var url1 = "http://rate-exchange.appspot.com/currency?from=" + lhs1 + "&to=" + rhs1

OTHER TIPS

Instead of

req.send(null);

Use

req.send();

If you want to try with jQuery:

var getCurrencyPair = function() {

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

  $.getJSON( url, function( data ) {
   console.log(data);
  });

};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top