JQuery serialize()不发送参数

时间:2017-11-29 12:25:47

标签: javascript jquery serialization

HTML:

<form class="form-horizontal" role="form" autocomplete="off" action="" method="POST" name="formular_comanda" id="formular_comanda">

<input type="number" class="form-control input-sm" name="inaltime_best" id="inaltime_best" placeholder="H (mm)" required="required" onchange="calculator_piese()" />

</form>

JS:

function calculator_piese() {
  var height = document.getElementById("inaltime_best");
  $.ajax({
    type: "POST",
    url: "calculator/panouri-simple/calcul-panouri-simple.php",
    data: $("#formular_comanda").serialize(),
    success: function(result) {
      document.getElementById("show_panels").innerHTML = result;
      console.log(height.value); // this return my input value
    },
    error: function(result) {
      console.log("Eroare:");
      console.log(result);
      console.log();
    }
  });
}

演算-panouri-simple.php

error_reporting(E_ALL);
$height = $_POST['height'];
var_dump($height); //this returns NULL

我有问题。我的php返回错误:

  

注意:第3行的未定义索引:高度... calcul-panouri-simple.php

console.log(height.value)会将值返回给我,但是从php var_dump我得到NULL

我不明白出了什么问题。

1 个答案:

答案 0 :(得分:0)

Because height field is not in your form so you can be use 

function calculator_piese() {
  var height = document.getElementById("inaltime_best");
  $.ajax({
    type: "POST",
    url: "calculator/panouri-simple/calcul-panouri-simple.php",
    data: $("#formular_comanda").serialize() + '&height=' + height,
    success: function(result) {
      document.getElementById("show_panels").innerHTML = result;
      console.log(height.value); // this return my input value
    },
    error: function(result) {
      console.log("Eroare:");
      console.log(result);
      console.log();
    }
  });
}