从ajax请求中获取的远程页面html中删除表单标记

时间:2012-02-09 16:14:43

标签: c# javascript jquery asp.net

我希望远程aspx页面的HTML到另一个我正在处理ajax请求的页面。我希望从远程页面HTML中删除表单标记,我也希望在远程页面上执行+脚本。

远程页面: Test.aspx文件:

    <%@ Page Language="C#" %>

<form id="form1" runat="server">
    <div id="wrapper">
<asp:textbox runat="server" ID="TextBox1"></asp:textbox>
</div>
<script type="text/javascript">

    alert('hello');
</script>

</form>

工作页面:

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-us">
<head runat="server">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="foo">
    </div>
    <script>


        $.ajax({ url: '/test.aspx',
            data: {},
            dataType: "html",
            success: function (response) {
                $('#foo').html('');
                var fragment = $(response).find('#wrapper');
                $('#foo').append(fragment);

            },
            error: function (xhr, ajaxOptions, thrownError) {

            }
        });
    </script>
    </form>
</body>
</html>
<script runat="server">


</script>

1 个答案:

答案 0 :(得分:1)

您是否尝试过使用jquery.load()?

http://api.jquery.com/load/

使用此功能,您可以在远程页面上指定容器的ID。像这样。

$(document).ready(function () {    
    $('#result').load('ajax/test.html #container');
});