【发布时间】:2011-07-27 22:55:47
【问题描述】:
我不知道标题是否足够清楚,但让我解释一下我要做什么。
我有两个用 C# 用 asp.net 编写的 webapp。
应用 A 具有以下 html。
<script type="text/javascript" id="blah" src="http://somServer/AppB/page.aspx?p=q"></script>
App B 收到上述请求,需要将 javascript 动态注入到上面的 script 标签中。我在 App B 的 page.aspx 中有以下代码,但它不起作用。我需要 App 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");
}
}
}
【问题讨论】:
-
你遇到什么样的错误?
-
你为什么要调用另一个 .aspx 页面?这是具体要求吗?
-
当您说不起作用时...资源是否加载但内容类型不正确?您能否附上来自 FireBug 的请求/响应标头的屏幕截图。
-
@Infotekka,没有错误但结果不是我预期的。
-
@TheGeek YouNeed,因为 AppB 将被许多其他网络应用程序使用/共享,这就是我将其构建为独立网络应用程序的原因。
标签: javascript asp.net