Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. [gelöst] HTTP Post JSON Daten

    NEWS

    • ioBroker goes Matter ... Matter Adapter in Stable

    • 15. 05. Wartungsarbeiten am ioBroker Forum

    • Monatsrückblick - April 2025

    [gelöst] HTTP Post JSON Daten

    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      Oberst_von_Gatow last edited by

      Hallo zusammen,

      erst einmal muss ich ein dickes Lob aussprechen.

      Ich bin erst vor ca. einer Woche auf ioBroker gestoßen und bin begeistert.

      Alles was ich bisher eingerichtet habe funktioniert einwandfrei.

      Jetzt wollte ich noch eines meiner alten Projekte einbinden.

      Ein RaspberrPi mit Webserver und Webinterface (JQuery Mobile) das als Lichtwecker funktioniert.

      Leider habe ich schon ewig kein Javascript mehr geschrieben und steh etwas auf dem Schlauch.

      Ich will nur eine PHP Datei mit JSON Daten versorgen.

      In meinem damaligen JQuery Script mach ich das mit AJAX.

      function writeData(data) {
          dtype = data["type"];
          $.ajax({
              type: "POST",
              url: "setdata.php",
              dataType: 'json',
              data: {
                  data: JSON.stringify(data),
                  type: dtype
              },
              success: function () {
                  alert("Thanks!");
              },
              failure: function () {
                  alert("Error!");
              }
          });
      }
      
      

      Wie mach ich das am einfachsten den in ioBroker JS?

      Ob Asynchron oder nicht ist mir dabei übrigends egal.

      Ich hab mal so angefangen:

      var http = require('http'); 
      var url = 'http://192.168.178.10/setdata.php';
      var dtype = "light";
      var myObj = { "type": "light", "lstatus": "on", "brightness": "40" };
      var myJSON = JSON.stringify(myObj);
      
      

      Aber wie mache ich den eigentlichen POST mit json?

      Vielen Dank

      Gruß

      1 Reply Last reply Reply Quote 0
      • L
        Lucky last edited by

        var request = require('request');
        
            var options = {
            url: 'http://192.168.178.10/setdata.php',
            method: 'POST',
            form:myObj 
        };
        
        request(options,function (error, response, body){
        
        //....
        
        });
        
        
        1 Reply Last reply Reply Quote 0
        • O
          Oberst_von_Gatow last edited by

          Hat geklappt!

          Vielen Dank für die Hilfestellung 🙂

          Gruß

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          Support us

          ioBroker
          Community Adapters
          Donate

          900
          Online

          31.6k
          Users

          79.5k
          Topics

          1.3m
          Posts

          2
          3
          2198
          Loading More Posts
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes
          Reply
          • Reply as topic
          Log in to reply
          Community
          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
          The ioBroker Community 2014-2023
          logo