如何在不刷新页面的情况下显示所选数据值

时间:2013-09-24 12:34:35

标签: javascript php jquery ajax

现在我通过刷新页面显示数据,但我想在不刷新页面的情况下显示数据,  window.location = '?action=suppliernetwork&supplier_id='+supplier_id+''; 是刷新页面的原因,任何人都可以通过刷新页面来指导我如何做到这一点。谢谢

HTML

<select name="supplierselect" id="supplierselect" style="margin:0px 0px 0px 0px;background-color:#C2FFC2;width:125px;"> 
    <option>--Select--</option> 
    <?php
$dbHost = 'localhost'; // usually localhost
$dbUsername = '';
$dbPassword = '';
$dbDatabase = '';
$db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect to Database Server.");
mysql_select_db ($dbDatabase, $db) or die ("Could not select database.");

$sql=mysql_query("select * from supplier");

while($row=mysql_fetch_array($sql))
{
 ?>
    <option id="supplierselect" value="<?php echo $row['supplier_id']; ?>"><?php echo $row['supplier_id']; ?></option>
    <?php } ?>


</select>

AJAX:

$(function() {  //  document.ready
    $("#supplierselect").on("change", function() {
        //var ID=$(this).attr('id');
        var supplier_id=$("#supplierselect").val();
        $.ajax({
            url: "suppliernetwork/select.php",
            type: "POST",
            data: {
                supplierselect: $(this).val()
            },
            success: function(data) {
                $("#display").html(data);
                window.location = '?action=suppliernetwork&supplier_id='+supplier_id+'';
                $("#flash").hide();
            }
        });
    });
});

0 个答案:

没有答案