0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

中古ノート、買ってみた。 その22

Last updated at Posted at 2025-09-18

概要

中古ノート買ってみた。
wsl1、入れてみた。
ubuntu18.04 、入れてみた。
apache2,php,sqlite、入れてみた。
phpフレームワーク、cheetanを見つけたので、やってみた。
CRUDを実装する。
json.php

写真

image.png

サンプルコード

<?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>




以上。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?