【问题标题】:Returning data from php with jquery and ajax使用 jquery 和 ajax 从 php 返回数据
【发布时间】:2013-01-28 11:29:41
【问题描述】:

我有问题。

我正在向 php 文件发出 Ajax 请求。我想在页面中显示结果,但我不能。也许我做错了什么。

代码如下:

<script type="text/javascript">
$(document).ready(function() {

    $("#submit_your_name").click(function() {

        $.ajaxSetup({
            cache: false
        });

        var name = $("#your_name").val();
        var data = 'your_name=' + name;

        if(name) {
            $.ajax({
                type: "POST",
                aSync: false,
                url: "1.php",
                data: data,
                success: function(data) {
                    $("#get_name").fadeOut();
                    $("#page_1").fadeIn();
                }
            });
        }

        return false;
    });
});

然后:

<div id="page_1" class="page_common" style="display: none;">

<p>Hello //I want to display the name here... , what are you after?</p>

我能做什么?有什么想法???

非常感谢!

【问题讨论】:

    标签: ajax forms request call


    【解决方案1】:

    首先从您的 ajax 函数中删除 aSync: false,。毕竟你是在做一个异步调用。

    如果没有任何问题,您的 div #page_1 包含您的进程文件 1.php 告诉它包含的内容。 (确保您是echoing 想要的结果。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-14
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      • 2013-02-25
      • 1970-01-01
      相关资源
      最近更新 更多