繁体   English   中英

如何从ashx处理程序文件中调用Java脚本函数

[英]How to call java script function from ashx handler file

我的功能

<script type="text/javascript">
function methodtocall(id) {
  // My code
}
</script>

我的ashx页面

public class sampleClass : IHttpHandler {

public void ProcessRequest (HttpContext context) {

    context.Response.ContentType = "text/plain";
// here i need to call that method
}
}

是的,我提到了net。但是没有解决方案。 大多数情况下,它们提供从方法到ashx或从ajax调用的解决方案。

谁能指导我正确的事情?

像这样引用

ClientScript.RegisterStartupScript(this.GetType(), "methodtocall", script, true);

根据代码,

public class sampleClass : IHttpHandler {

public void ProcessRequest (HttpContext context) {

context.Response.ContentType = "text/plain";
var id = "someid"; //implement the id that you want to pass to the Javascript function
ClientScript.RegisterStartupScript(this.GetType(), "methodtocall", id, true);
}
}

希望这可以帮助..!

参考链接: 链接

你可以这样

context.Response.Write("<script type='text/javascript'>function closeCurrentTab(){var conf=confirm('Are you sure, you want to close this tab?');if(conf==true){close();}}</script>");

context.Response.Write("<script type='text/javascript'>closeCurrentTab();</script>");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM