我不知道标题是否足够清晰,但让我解释我正在尝试做什么。如何为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