javascript - retrieve variable with ajax load function -
i want retrieve variable meja barang.php, saying 'notice: undefined index: meja in c:\xampp\htdocs\goeladjawa\barang.php on line 3'....
this javascript
var htmlobjek; var menu; var meja; var harga; var jumlah; var stok; $(function(){ $("#barang").load("barang.php"); $("#tambah").click(function(){ if(jumlah > stok) { alert("stok tidak terpenuhi"); $("#jumlah").focus(); exit(); } else if(jumlah < 1) { alert("jumlah pesan tidak boleh 0"); $("#jumlah").focus(); exit();} harga=$("#harga").val(); stok=$("#stok").val(); jumlah=$("#jumlah").val(); meja=$("#meja").val(); $("#status").html("sedang diproses. . ."); $("#loading").show(); $.ajax({ url: "tambah.php", data: {menu:menu,meja:meja,harga:harga,jumlah:jumlah}, cache: false, success: function(msg){ if(msg=='sukses'){ $("#status").html("berhasil disimpan"); } else{ $("#status").html("error"); } $("#barang").load("barang.php","meja"); } }); }); });
this barang.php
<?php include"db/koneksi.php"; $meja=$_get['meja']; $brg=mysql_query("select * pemesanan no_meja='$meja' ")or die (mysql_error()); echo "<thead> <tr> <td>nama barang</td> <td>jumlah beli</td> <td>subtotal</td> <td>tools</td> </tr> </thead>"; $total=mysql_fetch_array(mysql_query("select sum(subtotal) total pemesanan no_meja='$meja'")); while($r=mysql_fetch_array($brg)){ echo "<tr> <td>$r[nama_menu]</td> <td><input type='text' name='jum' value='$r[jumlah]' class='span2'></td> <td>$r[subtotal]</td> <td><a href='pk.php?op=hapus&kode=$r[nama_menu]' id='hapus'>hapus</a></td> </tr>"; } echo "<tr> <td colspan='3'>total</td> <td colspan='4'>$total[total]</td> </tr>"; ?>
the html
<select name="meja" id="meja"> <option>--pilih meja--</option>
this want, when click 'tambah' appeared on table based on 'pilih meja'
your load function seems wrong. check sample below.
$( "#result" ).load( "barang.php", { meja: '<pass value>' }, function() { alert( "load performed." ); });
Comments
Post a Comment