我不知道標題是否足夠清晰,但讓我解釋我正在嘗試做什麼。如何爲asp.net頁面提供javascript?
我有兩個用C#寫在asp.net中的webapps。
應用程序A具有以下html。
<script type="text/javascript" id="blah" src="http://somServer/AppB/page.aspx?p=q"></script>
應用程序B收到上面的請求,並需要動態注入JavaScript到上面的腳本標記。我在App B的page.aspx中有以下代碼,但它不起作用。我需要應用程序B返回純JavaScript,而不是HTML。
namespace AppB
{
public partial class Default : System.Web.UI.Page
{
if(!Page.IsPostBack)
{
Response.Clear();
Response.ClearContent();
REsponse.ClearHeader();
Response.AddHeader("content-type", "text/javascript");
var p = Request.Query["p"];
if(!string.IsNullOrEmpty(p))
{
this.Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "test", "alert('test');", false");
}
}
}
你得到什麼樣的錯誤? – Infotekka
你爲什麼要打另一個.aspx頁面?這是一個特定的要求嗎? – TheGeekYouNeed
當你說不起作用...資源是否加載但內容類型不正確?你可以附上FireBug的請求/響應頭文件嗎? – madcapnmckay