Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery AJAX-返回的HTML消失_Jquery_Ajax - Fatal编程技术网

jQuery AJAX-返回的HTML消失

jQuery AJAX-返回的HTML消失,jquery,ajax,Jquery,Ajax,我正在玩弄jQueryAjax,无意中发现了一个奇怪的地方(或者说我自己缺乏理解:)。以下是我的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:/

我正在玩弄jQueryAjax,无意中发现了一个奇怪的地方(或者说我自己缺乏理解:)。以下是我的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>

$(文档).ready(函数(){
$('#btnGo')。单击(函数(){
$.ajax({
键入:“获取”,
url:'GetValues.aspx',
contentType:'text/html',
成功:函数(html){$(“#Yo”).append(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();
        }
    }
}
namespace jQuery\u测试
{
公共部分类GetValues:System.Web.UI.Page
{
受保护的无效页面加载(对象发送方、事件参数e)
{
Response.ContentType=“text/html”;
回答。写(“”);
Response.End();
}
}
}
我所做的就是,当在主页上单击“Go”按钮时,我希望锚定标记放在段落旁边

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

干杯。
Jas.

使函数
返回false

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

            return false;
        })
    });

一旦处理程序代码运行,按钮将继续执行其正常功能(发布到页面)。如果在处理程序末尾返回false,事件将不会冒泡,按钮也不会发布。

除了触发Ajax调用外,您的按钮是否也会触发回发(因此页面将在没有添加文本的情况下重新绘制)?@JacobM-这类内容是否有最佳做法(使用按钮)。我对jQuery还很陌生,所以任何提示都将不胜感激。