我有这样的编码,编码是一个包含函数的类
<html lang="en">
<head>
<title>Ketidakpastian: Teorema Bayes</title>
<link href="../bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="../bootstrap/css/jquery.ui.all.css" rel="stylesheet">
<style type="text/css">
body {
padding: 10 200 10 200;
}
</style>
<script type="text/javascript" src="../bootstrap/js/jquery-1.8.2.js"></script>
<script type="text/javascript" src="../bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
$(".tooltipnya").tooltip({
trigger: 'hover',
placement: 'right'
});
});
$(function(){
$("#form-hitung").submit(function(){
$.ajax({
url:"teorema-bayes.php",
dataType: "json",
success: function(data){
cacar = "<ol>";
$.each(data, function(i,n){
cacar = cacar + "<li>"+n["pesan"]+" : "+n["hasil"]+"</li>";
});
cacar = cacar + "</ol>";
$(".result-cacar").append(cacar);
}
});
return false;
});
});
</script>
</head>
<body>
<?php
class TeoremaBayes {
private $cacar;
private $bintik2Cacar;
private $bintik2TidakCacar;
public function __construct($cacar, $bintik2Cacar, $bintik2TidakCacar) {
$this->cacar = $cacar;
$this->bintik2Cacar = $bintik2Cacar;
$this->bintik2TidakCacar = $bintik2TidakCacar;
}
public function setCacar($probCacar) {
$this->cacar = $probCacar;
}
public function getCacar() {
return $this->cacar;
}
public function setBintik2Cacar($probBintik2Cacar) {
$this->bintik2Cacar = $probBintik2Cacar;
}
public function getBintik2Cacar() {
return $this->bintik2Cacar;
}
public function setBintik2TidakCacar($probBintik2TidakCacar) {
$this->bintik2TidakCacar = $probBintik2TidakCacar;
}
public function getBintik2TidakCacar() {
return $this->bintik2TidakCacar;
}
//menghitung probabilitas tidak terkena cacar
public function notCacar() {
return $notCacar = 1 - $this->getCacar();
}
//menghitung prob. bintik2cacar kali prob. cacar
public function hitungBintik2Cacar() {
return $this->getBintik2Cacar() * $this->getCacar();
}
//menghitung prob. bintik2 tidak cacar kali prob. tidak cacar
public function hitungBintik2TidakCacar() {
return $this->getBintik2TidakCacar() * $this->notCacar();
}
//menghitung prob. terkena cacar
public function terkenaCacar() {
return round($this->hitungBintik2Cacar() / ($this->hitungBintik2Cacar() + $this->hitungBintik2TidakCacar()), 2);
}
//menghitung prob. tidak terkena cacar
public function tidakTerkenaCacar() {
return round($this->hitungBintik2TidakCacar() / ($this->hitungBintik2TidakCacar() + $this->hitungBintik2Cacar()), 2);
}
public function inputUser() {
?>
<h3>Ketidakpastian: Teorema Bayes</h3>
<p style="font-size: 16px">Menghitung Probabilitas seseorang terkena penyakit cacar atau tidak</p>
<form action="" method="post" id="form-hitung">
<table class="table" style="font-size: 16px;">
<tr>
<td>Probabilitas cacar</td>
<td><input type="text" name="probCacar" class="tooltipnya" style="height: 30px; width: 50px; text-align: right;" rel="tooltip" title="Masukkan peluang, misal 0.3"/></td>
</tr>
<tr>
<td>Probabilitas munculnya bintik-bintik diwajah maka cacar</td>
<td><input type="text" name="probBintik2Cacar" class="tooltipnya" style="height: 30px; width: 50px; text-align: right;" rel="tooltip" title="Masukkan peluang, misal 0.3"/></td>
</tr>
<tr>
<td>Probabilitas munculnya bintik-bintik diwajah maka tidak cacar</td>
<td><input type="text" name="probBintik2TidakCacar" class="tooltipnya" style="height: 30px; width: 50px; text-align: right;" rel="tooltip" title="Masukkan peluang, misal 0.3"/></td>
</tr>
<tr>
<td><input class="btn btn-primary" type="submit" value="Submit"/></td>
<td></td>
</tr>
</table>
</form>
<?php
}
public function dataJson() {
$data1 = array("pesan" => "Probabilitas tidak terkena cacar", "hasil" => $this->notCacar());
$data2 = array("pesan" => "Probabilitas terkena cacar jika ada bintik-bintik merah diwajah", "hasil" => $this->terkenaCacar());
$data3 = array("pesan" => "Probabilitas tidak terkena cacar jika ada bintik-bintik merah diwajah", "hasil" => $this->tidakTerkenaCacar());
$gabungData = array($data1, $data2, $data3);
}
public function tampilHasil() {
?>
<div class="result-cacar">
</div>
<?php
}
}
?>
</body>
然后我创建一个对象来调用已创建的类中的函数
<?php
require_once 'teorema-bayes.php';
$cacar = new TeoremaBayes($_POST['probCacar'], $_POST['probBintik2Cacar'], $_POST['probBintik2TidakCacar']);
$cacar->inputUser();
echo json_decode($cacar->dataJson());
$cacar->tampilHasil();
?>
但是调用结果的数据不行,是不是他的ajax和json有问题?
请帮我