LoginSignup
0
0

More than 5 years have passed since last update.

nasa space apps challenge その9

Last updated at Posted at 2017-03-25

概要

nasa space apps challenge に行けないので、勝手にハッカソンしてみる。
jsonをnode-redで永続化してみた。

写真

jj.JPG

global0

context.global.data = msg.payload.json;  
msg.res.header('Access-Control-Allow-Origin', '*');
msg.res.send("{}");
return msg;

global1

msg.res.header('Access-Control-Allow-Origin', '*');
var data = context.global.data;
msg.res.send(JSON.stringify(data));
return msg;

サンプルコード

function get() {
    var now = new Date();
    $.ajax({
        type: 'GET',
        url: 'http://ohijs0.paas.jp-e1.cloudn-service.com/getdb?' + now,
        success: function(res) {
            document.getElementById("src").value = res;
        },
        error: function(res) {
            alert('err1');
        }
    });
}
function put() {
    var src = document.getElementById("src").value;
    var json = JSON.parse(src);
    json.push({
        "name": "test1",
        "body": "desu1"
    });
    var str = JSON.stringify(json);
    $.ajax({
        type: 'POST',
        url: 'http://ohijs0.paas.jp-e1.cloudn-service.com/putdb',
        dataType: 'json',
        data: {
            json
        },
        success: function(data) {
            alert("ok");            
        },
        error: function(res) {
            alert("err0");
        }
    });
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0