我可以在.js文件中编写ASP代码吗? [英] Can I write ASP code in a .js file?

查看:162
本文介绍了我可以在.js文件中编写ASP代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在.js文件中编写ASP代码吗?或者,如果有什么方法可以更新.js文件中的数据库.

Can I write ASP code in a .js file. Or if there is any way through which I can update database in a .js file.

推荐答案

从技术上讲,是的.

您需要将js扩展名添加到IIS和web.config文件:

You need to add the js extension to IIS and the web.config file:

<system.web>
<httpHandlers>
<add verb="*" path="*.js" type="System.Web.UI.PageHandlerFactory"/>
</httpHandlers>

另一个选项(我建议)是请求一个.asp文件,如下所示:

The other option (which I recommend) is request an .asp file, like this:

<script type="text/javascript" src="yourASPfile.asp"></script>

然后yourASPfile.asp将发送一个javascript标头:

And yourASPfile.asp would send a javascript header:

<%
Response.ContentType = "application/x-javascript"
%>

尽管从技术上讲,您无需设置标题.

Although technically, you don't need to set the header.

现在您可以编写asp/javascript,然后由提供给浏览器的服务器解析,以供使用.

Now you can write asp/javascript and it gets parsed by the server THEN delivered to the browser to be used.

这篇关于我可以在.js文件中编写ASP代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆