2012-02-09 11 views
1

リモートのaspxページのHTMLをajaxリクエストを処理している別のページにしたい。私はフォームタグをリモートページからも削除したいHTML 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

ASPまたはjQueryで編集していますか? jQueryなら、これを試してみてください:http://stackoverflow.com/a/5601929/1013082 – MetalFrog

+0

私の文脈で私にも同じことを説明できますか? –

答えて

1

は)(あなたがjquery.loadを使用してみましたか?これで

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

リモートページ上のコンテナのIDを指定することができます。このような。

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

この行で "$( '#foo')。load( '/ test.aspx#form1');"警告は発射されません。 –

+0

これは、asp.netがフォームのようなサーバーバウンドアイテムのIDを変換するためです。

のようにアラートの周りにdivを置いてから$( '#foo')を呼び出します。load( '/ test.aspx #divalert'); –

+0

アラートがまだ表示されません。ここでは、リモートページの私のコードは<%@ページ言語= "C#の" %> <フォームID = "Form1の" にrunat = "サーバー">