繁体   English   中英

php-Ajax:发送Float数据并获取响应

[英]php-Ajax: Send Float data and get response

Ajax脚本

<script>
function tankdip(str) {
    if (str == "") {
        document.getElementById("open").innerHTML = "";
        return;
    } else { 
    var num = parseFloat(str);
        var tank = document.getElementById("pumps"+count).value;

        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("open").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET","open.php?open="+num+"&tank="+tank,true);
        xmlhttp.send();
    }
}
</script>

HTML表格

<td><input type="text" name="odip[]"   id="odip" data-srno="1" class="form-control input-sm " onkeyup="tankdip(this.value)" required></td>
<td><select  name="open[]"  id="open" data-srno="1" class="form-control input-sm " readonly></select></td>

open.php

<?php
include "connect.php";
$con=mysqli_connect("$host", "$username", "$password","$db_name")or die("Your Connection is in error");
$open = $_GET['open'];
$tank    = $_GET['tank'];
$sql     = mysqli_query($con,"SELECT dip,cap from $tank where dip = '$open'");
while ($row = mysqli_fetch_array($sql))
{
$combo.="<option >" . $row[1]. "</option>";
}

echo $combo;

?>

我想使用ajax获取对应的“ odip”值的“ open”值。 但是,当我尝试发送float(12.34)时,它变为(12)。我希望将日期作为Float发送。

尝试

function tankdip(str) {
  console.log("Input str:", str);

您确定什么str是浮动的?

也可能是这样,某些表中的哪个字段dip具有INT类型?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM