【问题标题】:How can I show the result of an AJAX request in a dialog box? [closed]如何在对话框中显示 AJAX 请求的结果? [关闭]
【发布时间】:2015-04-16 18:51:43
【问题描述】:

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

$(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。

【问题讨论】:

  • 请重新组织您的代码。
  • 您还应该说明具体问题是什么。
  • 这里的反对票有点苛刻。我见过比这个更糟糕的问题。
  • user1468327,如果您在发布之前花时间格式化您的代码,您本可以为自己节省很多很多反对票。
  • 好的,我明白了。下次我会记住的

标签: jquery ajax popup


【解决方案1】:
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");
        });
    });
});

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

【讨论】:

  • 对不起哥们,我想要像facebox这样的花哨的对话框请帮忙???
  • @user1468327。 Stack Overflow 不是让人们为您完成工作或家庭作业的地方。这是一个提出特定问题并希望获得该特定问题答案的地方。在这种情况下,robinp7720 已经超出了回答您的问题所需的范围。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多