jQuery AJAX-返回的HTML消失了

我在用jQuery AJAX搞怪,偶然发现了一个奇怪的地方(或者我缺乏理解:).这是我的ASPX主页的代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="jQuery_Test.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#btnGo').click(function() {
                $.ajax({
                        type: "GET",url: 'GetValues.aspx',contentType: 'text/html',success: function (html) { $("#Yo").append(html); }
                });
            })
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <p id="Yo">Yo there!</p>
        <br />
        <a href="#" class="yo">Yo there!</a>
        <br />
        <a href="#">I'm in a DIV!</a>
        <br />
        <button id="btnGo">Go</button>
    </div>
    <br />
    <br />
    <a href="#">I'm not in a DIV!</a>
    </form>
</body>
</html>

这是“ GetValues.aspx”页面的代码背后:

使用系统;

namespace jQuery_Test
{
    public partial class GetValues : System.Web.UI.Page
    {
        protected void Page_Load(object sender,EventArgs e)
        {
            Response.ContentType = "text/html";
            Response.Write("<a href='#'>Hello World</a>");
            Response.End();
        }
    }
}

我正在做的是,当单击主页上的“开始”按钮时,我希望将锚标记放置在段落旁边.

该代码确实有效,但是锚点“ Hello World”出现约1秒钟,然后消失.有人可以指出我做错了什么吗?我正在使用VS 2010 Ultimate随附的jQuery-1.3.2.mins.js.

干杯.
贾斯

最佳答案
使您的函数返回false;

    $(document).ready(function () {
        $('#btnGo').click(function() {
            $.ajax({
                    type: "GET",success: function (html) { $("#Yo").append(html); }
            });

            return false;
        })
    });

相关文章

1.第一步 设置响应头 header(&#39;Access-Control-Allow...
$.inArray()方法介绍 $.inArray()函数用于在数组中搜索指定的...
jquery.serializejson.min.js的妙用 关于这个jquery.seriali...
JS 将form表单数据快速转化为object对象(json对象) jaymou...
jQuery插件之jquery.spinner数字智能增减插件 参考地址:http...