S
S
svagafox2021-02-21 20:13:47
AJAX
svagafox, 2021-02-21 20:13:47

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 "";
      }

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

JS
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

2 answer(s)
R
Rsa97, 2021-02-21
@Rsa97

onclick=" checkData ()"
function getData (x,y,r)

N
no_one_safe, 2021-02-22
@no_one_safe

Try submitting the form via formData

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question