2

スクリプトを提供したいクライアントがたくさんいるので、CusotmerIDに基づいて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;
        }
    }
}
4

1 に答える 1

7

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);
}
于 2012-06-07T07:16:39.917 に答える