簡體   English   中英

使用ASP.net處理程序動態創建JS文件

[英]Dynamically create JS file using ASP.net Handler

我有很多客戶想要給他們腳本,所以我想根據客戶編號創建JS文件。 所以我可以退貨,它可以直接在客戶端執行。 客戶端可以是任何人,PHP,HTML,ASP.net

問題是,當我瀏覽此鏈接時,它給了我JS字符串,但是在客戶端,此腳本未像測試那樣執行,我發出了警報,此警報未在客戶端顯示


顧客

<head>
    <script src="http://localhost:12604/JSCreator/Handler.ashx?CustomerID=123" type="text/javascript"></script>
    <title></title>
</head>

處理程序文件

public class Handler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        string CustomerId = context.Request["CustomerId"].ToString();
        string jscontent = JSFileWriter.GetJS(CustomerId); // This function will return my custom js string

        context.Response.ContentType = "text/javascript";
        context.Response.Write(jscontent);
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

ContentType應該是application/javascript

public void ProcessRequest(HttpContext context)
{
    string CustomerId = context.Request["CustomerId"].ToString();
    string jscontent = JSFileWriter.GetJS(CustomerId); // This function will return my custom js string

    context.Response.ContentType = "application/javascript";
    context.Response.Write(jscontent);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM