Search code examples
javascriptjquerypebble-watchcloudpebblepebble-js

using jQuery in PebbleJS apps


How can I add the jQuery library to my PebbleJS apps? Here's my code:

var UI = require('ui');
var ajax = require('ajax');
var $=require('jQuery');

$.getJSON(URL);
var card = new UI.Card({
  title:'last.fm stat',
  subtitle:'Fetching...'
});
card.show();

Here's the error I receive:

[INFO] ocess_manager.c:368: Heap Usage for App <lastfm sta: Total Size <48584B> Used <6256B> Still allocated <28B>
[PHONE] pebble-app.js:?: JavaScript Error:
Error: Cannot find module 'jQuery'
    at Object.loader.require (loader.js:34:11)
    at require (loader.js:41:48)
    at Object.loader (app.js:9:7)
    at Object.loader.require (loader.js:44:10)
    at require (loader.js:41:48)

Solution

  • You cannot use jQuery. PebbleJS uses the jQuery Mobile specifications of jQuery natively. You do not need to require it in the app as it is already a part of it.

    That said, you may want to research and understand the difference between the two, as some functionality has been removed for the mobile side. One specific instance I remember the most is jQuery Mobile has responseText but not responseXML. This is why many people have a lot of work arounds in place to manage XML feeds in their apps when they are unable to retrieve JSON from an API.