Coder Social home page Coder Social logo

support of jsonp about pebblejs HOT 2 OPEN

pebble avatar pebble commented on July 23, 2024
support of jsonp

from pebblejs.

Comments (2)

Meiguro avatar Meiguro commented on July 23, 2024

According to their docs, it looks like by not specifying ?callback=<identifier>, OpenRemote will respond with plain JSON. They just decided to show JSONP as their primary use case.

It's possible that some of their endpoints only support JSONP. You're not out of luck. You can specify, for example, a function "receivePanels" such as var receivePanels = function (x) { console.log(x); }. Then in your ajax call, you would eval their response. This is evil, but that is how JSONP works, and why I don't recommend using JSONP. The example ajax:

ajax(
  {
    url: 'http://localhost:8080/controller/rest/panels?callback=receivePanels'
  },
  function success(data, status) {
    eval(data);
  },
  function failure(error, status) {
    console.log('Error: ' + status + ' ' + error); 
  }
)

If CloudPebble does not let you use eval, you may use the new Function(source)() trick. For the function trick, if your callback function is locally scoped, you will need to pass it.

Alternatively, if their JSON in the JSONP response is well formed, you may simply regex match their JSON out of the response data. This is also nasty, but not as evil. For example /\w+\s*&&\s*\w+\((.*)\)/. With the first match group, you can then call JSON.parse on it.

Let me know if any of these solutions work for you. I may decide to add JSONP support, but I hope that JSON APIs replace them.

from pebblejs.

gwijsman avatar gwijsman commented on July 23, 2024

Hi Meiguro,
Thanks for your answer that really helped me!
I tested the evil solution (for me the easy way...)
Removing the callback is not helping me because OpenRemote supplies XML (Talking about evil...)
The suggested recievePanels function gets the nicely parsed object as parameter. Evil or not it works for me!
It must be possible to configure this way a set of switches in OpenRemote and give your pebble watch a dynamic interface to control your domotica.
Thanks for developing and maintaining pebble.js! great initiative!

from pebblejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.