Answer the question
In order to leave comments, you need to log in
The code works with GET but doesn't work with POST. Why?
The task is to check and display values from the form on one page. Everything works with the GET method, but not with the Post method.
I am attaching the POST code. What's my mistake? Why if you change to GET everything works as it should?
PHP
session_start();
if (!isset($_SESSION['results'])){
$_SESSION['result'] = [];
}
$startTime = microtime();
if (isset($_POST["x_value"]) && (isset($_POST["y_value"])) && isset($_POST["r_value"])){
$x = $_POST["x_value"];
$y = $_POST["y_value"];
$r = $_POST["r_value"];
$result = "";
if (checkParameter($x, $y, $r)){
if (checkArea($x,$y,$r))
$result = "yes";
else $result = "no";
$end = calcDuration($startTime, microtime()) * 1000;
$date = date('H:i:s');
$_SESSION['results'][] = array(
'x' => $x,
'y' => $y,
'r' => $r,
'result' => $result,
'date' => $date,
'Time' => $end
);
} else echo "";
}
<form method="post">
<table id="valueTable" class="bord">
<thead><td colspan="5"><h2>1017</h2></td></thead>
<!-- <tbody> -->
<tr>
<td>область:</td>
<td><img src="image/png1.png" align="" class="newone"></td>
</tr>
<tr>
<td></td>
<td>изменение X:
<select class = "newone" name="X" id="Select_X">
<option value="-2" id="X2">-2</option>
<option value="-1.5" id="X_1_5">-1.5</option>
<option value="-1" id="X_1">-1</option>
<option value="-0.5" id="X_0_5">-0.5</option>
<option value="0" id="X0">0</option>
<option value="0.5" id="X0_5">0.5</option>
<option value="1" id="X1">1</option>
<option value="1.5" id="X1_5">1.5</option>
<option value="2" id="X2">2</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td colspan="">изменение Y:<input name="Y" id="y" class = "newone" type="text" placeholder="значение от -5 до 3" maxlength="6">
</td>
</tr>
<tr>
<td></td>
<td colspan="">изменение R:<input name="R" id="r" class = "newone" type="text" placeholder="значение от 2 до 5" maxlength="6">
</td>
</tr>
<tr>
<td></td>
<td colspan="2">
<input type="button" id="button" name="button" onclick="checkData()" value="check"
style="background: rgb(253, 234, 227);border-radius: 3px;color: #000000;font-weight: bold;padding: 6px 20px;text-align: center;">
</td>
</tr>
</form>
function getData(x,y,r){
$.ajax({
method: "POST",
url: "script.php",
data:{x_value:x, y_value:y, r_value:r}}).done(function(result){
$('#prevAns').html(result)
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question