当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 在一般处理程序(ashx)中弹出js提示语

在一般处理程序(ashx)中弹出js提示语

2017年12月12日  | 移动技术网IT编程  | 我要评论

在提交form表单时,比如前台是$("form").submit()同步提交的时候,这个是没有回掉函数的,那么我们只能在后台提示,在前台显示,自己作为一个参考吧

public class script
   {
     public static void alert(string message)
     {
       responsescript("alert('" + message + "');window.location = '弹出提示语后,点击确认跳到你想跳的页面';");
     }
     public static void responsescript(string script)
     {
       httpcontext.current.response.write("<script type=\"text/javascript\">\n//<![cdata[\n");
       httpcontext.current.response.write(script);
       httpcontext.current.response.write("\n//]]>\n</script>\n");
     }
   }

还有就是将一般处理程序默认的 //context.response.contenttype = "text/plain";改为
            context.response.contenttype = "text/html";  

我们调用的时候直接: 

script.alert("你的提示语!");

ps:js中$.ajax调用一般处理程序(.ashx)

$.ajax({
          type: "post",
          url: "/tools/actapply.ashx",
          data: "txthdmoney=" + $.trim($("#hdmoneyx")[0].value)+"&sxf=2",
          success: function (result) {            
          }
        });

.ashx后台接收数据

  protected decimal hdmoney;
    protected decimal hdsxf;
    /// <summary>
    /// 请求处理
    /// </summary>
    /// <param name="context"></param>
    public void processrequest(httpcontext context)
    {
      withdrawal withdra = new withdrawal();
      context.response.contenttype = "text/plain";
      hdmoney = convert.todecimal(context.request.params["txthdmoney"].tostring());
      hdsxf = convert.todecimal(context.request.params["sxf"].tostring());
      saveact();
    }
    public bool isreusable
    {
      get
      {
        return false;
      }
    }

总结

以上所述是小编给大家介绍的在一般处理程序(ashx)中弹出js提示语,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网