概要
中古ノート買ってみた。
wsl1、入れてみた。
ubuntu18.04 、入れてみた。
apache2,php,sqlite、入れてみた。
phpフレームワーク、cheetanを見つけたので、やってみた。
CRUDを実装する。
json.php
写真
サンプルコード
<?php
require_once 'cheetan.php';
function action(&$c) {
if ($c->raw() > '')
{
$json = json_decode($c->raw());
$param = array ('name' => $json->name, 'age' => $json->age);
$c->db->insert('test')->values($param)->execute();
$da = $c->db->select('*')->from('test')->execute();
$c->sendJson($da);
}
}
?>
<form method="" action="">
name<br />
<input type="text" id="na" name="test/name" value="oota" /><br />
age<br />
<input type="text" id="age" name="test/age" value="19" /><br />
<input type="button" onclick="run()" value="new" />
</form>
<textarea id="out" cols="60" rows="12" >
</textarea>
<script>
var out = document.getElementById('out');
var na = document.getElementById('na');
var age = document.getElementById('age');
var endpoint = "http://localhost/json.php";
function run() {
var src = '{"name":"' + na.value + '", "age":"' + age.value + '"}';
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200)
{
out.value = xhr.responseText;
na.value = "";
age.value = "";
}
else
{
}
};
xhr.open("POST", endpoint, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(src);
}
</script>
以上。