如何在对话框中显示AJAX请求的结果?

时间:2015-04-16 18:51:43

标签: jquery ajax popup

我在服务器上有一些想要在对话框中打印的数据,我想要的是以下内容。

$(function() {
    $("#checkreservatoion").click(function() {
        // getting selected date
        var selected_date = $("#sd").val(); 

        // getting route details    
        var selected_route = $("#route option:selected").val(); 

        // getting the details of seats
        var selected_sites = $("#qty option:selected").text();
        $.post("abc.php", {
            date: selected_date,
            route: selected_route,
            seats: selected_sites 
        }, function(ajaxresult) {
            //getting ajax result and printing as html 
            $("#postrequest").html(ajaxresult);
        });
    });
});

但是这段代码不起作用,其中#postrequest是作为jQuery插件的模型的div。

1 个答案:

答案 0 :(得分:4)

alert(ajaxresult)

而不是

$("#postrequest").html(ajaxresult);

它会显示一个基本的对话框,但通常不鼓励使用

或更时尚的一个: HTML:

<div class="dialogue">
    <div class="header">
        This is an alert!
    </div>
    <div class="body">

   </div>
</div>

的CSS:

.dialogue{
    position:none;
    width:500px;
    height:500px;
    left:50%;
    top:50%;
    margin-left: -250px;
    margin-top:-250px;
}
.dialogue > .header{
    background: blue;
    color: white;
    height:20px;
    width:100%;
}
.dialogue > .body{
    width:100%;
    height:480px;
}

JS

$(function() {
    $("#checkreservatoion").click(function() {
        // getting selected date
        var selected_date = $("#sd").val(); 

        // getting route details    
        var selected_route = $("#route option:selected").val(); 

        // getting the details of seats
        var selected_sites = $("#qty option:selected").text();
        $.post("abc.php", {
            date: selected_date,
            route: selected_route,
            seats: selected_sites 
        }, function(ajaxresult) {
            //getting ajax result and printing as html 
            $(".dialogue > .body").html(ajaxresult);
            $(".dialogue").css("position","fixed");
        });
    });
});

我没有测试过这段代码,但它应该可以运行

相关问题