BMIに関連する体重の計算を行うphpプログラムの間違えている点やアドバイスが欲しい

前提

BMIに関連する体重の計算を行うphpプログラムの間違えている点やアドバイスが欲しいです。

実現したいこと

・getJSON()メソッドで通信する
・サーバ側で計算結果をJSON形式でブラウザに返す
・BMIに関する体重の計算を、サーバ側のphpプログラムで行い、JavascriptでWebブラウザ上で計算して はいけない。

発生している問題・エラーメッセージ

エラーメッセージ

該当のソースコード

php

<!DOCTYPE html><html lang="ja"><head><meta charset="UTF-8"><title>体重計算</title><link href="./style.css" rel="stylesheet"><script src="./jquery-3.6.1.min.js"></script> <script> $(function(){// jQueryを使用して、読込ボタンがクリックされたら処理を行ないます。 $("#calc").on("click", function{ $.getJSON("bmi.php", {height:$("#height").val()}, function(data){ // 行のオブジェクトを生成します。 var tr = $("<tr>");// 列のオブジェクトを生成して行に追加します。 var td_low = $("<td>").text(data.low); tr.append($("#bmi-result").html(data.low)); var td_mid = $("<td>").text(data.mid); tr.append($("#bmi-result").html(data.mid)); var td_hi = $("<td>").text(data.hi); tr.append($("#bmi-result").html(data.hi));// 行のオブジェクトをテーブルに追加します。 $("#listbox").append(tr); }); }); });</script></head> <body><div id="bmi-result"><form method="get" action="bmi.php"><p>身長(m): <input type="text" value="" id="height" name="height"><input type="button" value="計算" id="calc"></form></p><table id="listbox"><tr><th>低体重(kg)</th><th>標準体重(kg)</th><th>肥満(kg)</th></tr></table></form></div></body></html> ```2つ目のプログラム <?phpif (! isset($_SERVER['HTTP_X_REQUESTED_WITH']) || $_SERVER['HTTP_X_REQUESTED_WITH'] !== 'XMLHttpRequest') { die(json_encode(array('status' => "Illegal Call 不正な呼び出しです")));}$value = array('low'=>height*height*18.5, 'mid'=>height*height*22, 'hi'=>height*height*25.0);header("Content-Type: application/json; charset=UTF-8");header("X-Content-Type-Options: nosniff");echo json_encode($value);

試したこと

実行して計算ボタンを押しても何も動作が行われない。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

コメントを投稿

0 コメント