0

我有一个如下所示的弹出表单 在此处输入图像描述

这里的代码

*<div   class="popup_window_css" id="sample" display="none">
<table class="popup_window_css">
<tr    class="popup_window_css">
<td    class="popup_window_css">
<div   class="popup_window_css_head"><img src="../../images/close.gif" alt="" width="9" height="9" />Aksi</div>
<div   class="popup_window_css_body"><div style="border: 1px solid #808080; padding: 6px; background: #FFFFFF;">
<div>
Werehouse Product
<br><select id="wp" name="wp" >
        <option selected>- Jenis Werehouse -</option>
        <?php
        $q = mssql_query("select WHSName from tblSPDMstWarehouseProduct Order by WHSID"); 

        while ($r = mssql_fetch_array($q)){
        echo "<option value=$r[WHSName]>$r[WHSName]</option>";
        }
        ?>
</select>
</br>
Posisi
     <br><input type="text" id="posisi" name="posisi" readonly/></br>
Product ID
     <br><select id="pid" name="pid">
        <option selected = "selected" >- Produk ID -</option>
            <?php
            $q = mssql_query("select ProductID from tblMstProduct Order by ProductID"); 

            while ($r = mssql_fetch_array($q)){
            echo "<option value=$r[ProductID]>$r[ProductID]</option>";
        }?>
        </select>
    </br>
Product Name
     <br><input type="text" id="pname" name="pname" size="65" readonly/>
     </br>
Production Date
<br><input type='text' id="tgl" name="tgl"></br>
<button id="save">Save</button>
<button id="view">View</button>
<button id="delete">Delete</button>
<span id="status"></span>
<img src="../../images/loading.gif" id="loading" style="display:none">
</div>
<div class="popup_window_css_foot"></div></td></tr></table>
</div>*

使用 ajax.jquery 作为控制事件。像 $("#save").click(function(){.....});

<script type="text/javascript">
var wp;
var posisi;
var pid;
var pname;
var pdate;
var datanya;
$(document).ready(function(){
//jika tombol save diclick
$("#save").click(function(){
//ambil nilai-nilai dari masing-masing input
wp = $("#wp").val();
if(wp==="- Jenis Werehouse -"){
alert("Pilih dulu jenis werehouse");
exit();
}
posisi = $("#posisi").val();
pid = $("#pid").val();
if(pid==="- Produk ID -"){
alert("Pilih dulu ID Produk");
exit();
}
pname = $("#pname").val();
if(pname==""){
alert("Pilih dulu ID Produk");
exit();
}
pdate=$("#pdate").val();
if(pdate==""){
alert("Isi dulu tanggal inputnya");
exit();
}

这里的问题

 datanya = "wp="+wp+"&posisi="+posisi+"&pid="+pid+"&pname="+pname;
    datanya = datanya+"&pdate="+pdate;
    //tampilkan status Updating dan animasinya
    $("#status").html("Proses...");
    $("#loading").show();
    $.ajax({
    type:"POST",
    url: "aksi.php",
    data: "op=save"+datanya,
    cache: false,
    success: function(msg){
    if(msg=="sukses"){
    $("#status").html("Data Berhasil Disimpan...");
    }else{
    $("#status").html("ERROR..penyimpanan data GAGAL!");
    }
    $("#loading").hide();
    }
    });
    });
    });
    </script>

在这个脚本上,我尝试通过元素 id 获取值并使用 POST 作为方法。这里 aksi.php 代码

    <?php
    //conect to database
    //get the value

        $op = $_POST['op'];
        if($op == "save"){
        $WH = htmlspecialchars($_POST['wp']);
        $Posisi = htmlspecialchars($_POST['posisi']);
        $ProductID = htmlspecialchars($_POST['pid']);
        $ProductName = htmlspecialchars($_POST['pname']);
        $ProductionDate = htmlspecialchars($_POST['pdate']);
        $save = mssql_query("Insert tblTrnProduct values('$ProductID', '$ProductName', '$WH', '$Posisi', '$ProductionDate')
        WHERE Posisi='$Posisi'");
        if($save){
        echo "sukses";
        }else{
        echo "error";
        }
        }
?>

在 aksi.php 上没有记录任何值。c'z 当我使用时<?php print_r($_POST) ?>有一个空结果。当然,当我在浏览器中运行它时,总是说“ERROR..penyimpanan data GAGAL”。有什么问题?请建议...带有代码示例将更加感激..

4

1 回答 1

0

&我认为您在 ajax 发布数据值中缺少 a :data: "op=save&"+datanya,

JQuery 带有一个非常有用的方法$.param它将编码您的查询字符串

在你的情况下:

var datanya = {"op": "save", "wp": wp, "posisi": posisi, "pid": pid, "pname": pname, "pdate": pdate}
[...]
$.ajax({
  data: $.param(datanya) ,
  [...]
});
于 2013-04-16T09:29:03.287 回答