首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

ashx怎么执行JavaScript代码

2012-09-11 
ashx如何执行JavaScript代码如下面的代码, 当执行完成后,在面会出现scriptalert(删除成功!) window.

ashx如何执行JavaScript代码
如下面的代码, 当执行完成后,在面会出现"<script>alert('删除成功!'); window.history.go(-1);</script>"字样, 而不是执行该段JavaScript代码..
要怎么做才能让它执行?

C# code
<%@ WebHandler Language="C#" Class="Style_Sheet_Attachment_Del" %>using System;using System.Web;using System.Data;using System.Data.SqlClient;public class Style_Sheet_Attachment_Del : IHttpHandler {    public void ProcessRequest(HttpContext context)    {        context.Response.ContentType = "text/plain";        try        {            if (context.Request.QueryString["Style_Sheet_Attachment_Id"] == null)            {                context.Response.Write("<script>alert('请以 QuantityString 方式传入 Style_Sheet_Attachment_Id'); window.history.go(-1);</script>");            }            else            {                string cmdText = "DELETE FROM Style_Sheet_Attachment WHERE Id = @Id";                DataHelper.SqlHelper.ExecuteNonQuery(CommonFun.ConnectionString, CommandType.Text, cmdText, new SqlParameter("@Id", context.Request.QueryString["Style_Sheet_Attachment_Id"]));                context.Response.Write("<script>alert('删除成功!'); window.history.go(-1);</script>");            }        }        catch (Exception ex)        {            context.Response.Write(ex.Message);        }    }     public bool IsReusable {        get {            return false;        }    }}


[解决办法]
直接把context.Response.ContentType = "text/plain";去掉就可以
C# code
<%@ WebHandler Language="C#" Class="Style_Sheet_Attachment_Del" %>using System;using System.Web;using System.Data;using System.Data.SqlClient;public class Style_Sheet_Attachment_Del : IHttpHandler {    public void ProcessRequest(HttpContext context)    {        try        {            if (context.Request.QueryString["Style_Sheet_Attachment_Id"] == null)            {                context.Response.Write("<script>alert('请以 QuantityString 方式传入 Style_Sheet_Attachment_Id'); window.history.go(-1);</script>");            }            else            {                string cmdText = "DELETE FROM Style_Sheet_Attachment WHERE Id = @Id";                DataHelper.SqlHelper.ExecuteNonQuery(CommonFun.ConnectionString, CommandType.Text, cmdText, new SqlParameter("@Id", context.Request.QueryString["Style_Sheet_Attachment_Id"]));                context.Response.Write("<script>alert('删除成功!'); window.history.go(-1);</script>");            }        }        catch (Exception ex)        {            context.Response.Write(ex.Message);        }    }     public bool IsReusable {        get {            return false;        }    }}
[解决办法]
直接把context.Response.ContentType = "text/plain";去掉就可以
恩 对的
不然直接输出文本

热点排行