NEWS
async await Probleme
-
Moin...
in meiner tools.js habe ich folgendes stehen:
var iobrokerObjectJSON = new function () { this.get = async function (obj) { var x = null; await fetch(ioBrokerURL_simpleAPI+'getPlainValue/'+obj).then (function(response) { return response.json(); }).then (function(data) { x = data; }).catch (function() { console.log("Error -> iobrokerObectJSON.get"); }); return JSON.parse(x); }; }
in meiner HTML:
var data = ''; loadObj(); function loadObj() { data = iobrokerObjectJSON.get('0_userdata.0.Räume.Arbeitszimmer.Heizung.Profile'); console.log(data); } .... ....
leider wird nicht auf eine Antwort gewartet.
Wie muss die Funktion richtig aussehen?
-
@ljmarkus said in async await Probleme:
var response = await fetch(ioBrokerURL_simpleAPI+'getPlainValue/'+obj); return JSON.parse(response.json());
Aber: was machst du da genau? Weshalb SimpleAPI?
Und: schau dir das mal an: https://gist.github.com/AlCalzone/d14b854b69ce5e8a03718336cc650a95
-
@ljmarkus said in async await Probleme:
Wie muss die Funktion richtig aussehen?
gut und richtig muss die aussehen... entschuldige meine Reaktion aber meine Glaskugel ist gerade im Keller... und mit dem codeschnippsel kann keiner was anfangen..
also bitte komplett alles oder zumindest so das man die variablen zu der methode zu der klasse nachvollziehen kann
-
@ljmarkus Sehe ich das richtig, daß Du von einem entfernten Rechner iobroker Objekte abfrägst ?
axios wäre ein Weg :
const axios = require('axios'); axios.get(url) .then((response) => { console.log(response.data); }) .catch(function (error) { // handle error console.log(error); })