通过HTML调用C# [架构]
先看一下HTML代码:
<html>
<head>
<title>Demo for how to call C# business from html page</title>
<script src="http://www.zivosft.com/core/lib.js"></script>
</head>
<body>
<form id="default" action="Zivsoft.Business.DemoShow.AddSample">
<input id="a" type="text">+
<input id="b" type="text">+
<input id="c" type="text">=
<input id="txt" type='text'>
<input type="button" id="add" value="submit" onclick="CallBusiness();">
</form>
</body>
</html>
<head>
<title>Demo for how to call C# business from html page</title>
<script src="http://www.zivosft.com/core/lib.js"></script>
</head>
<body>
<form id="default" action="Zivsoft.Business.DemoShow.AddSample">
<input id="a" type="text">+
<input id="b" type="text">+
<input id="c" type="text">=
<input id="txt" type='text'>
<input type="button" id="add" value="submit" onclick="CallBusiness();">
</form>
</body>
</html>
再看一下HTML界面:
以上是一个非常简单的Demo,来演示通过HTML界面构造三个输入框,并调用后代C#逻辑Zivsoft.Business.DemoShow.AddSample实现三个数相加求和的功能。
下面看一下后台C#业务逻辑:
namespace Zivsoft.Business.DemoShow
{
public class AddSample:BaseControl
{
public class AddSample:BaseControl
{
private void Add_Click(IComponent com)
{
this.txt.Value = System.Convert.ToInt32(this.tba.Value)
private void Add_Click(IComponent com)
{
this.txt.Value = System.Convert.ToInt32(this.tba.Value)
+ System.Convert.ToInt32(this.tbb.Value)
+ System.Convert.ToInt32(this.tbc.Value);
}
}
}
}
最后看看一段JavaScript代码:
var url = http://www.zivsoft.com/cloudserver/default.aspx;
req.open("POST", url, async);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
while (reqData.indexOf('/') != -1)
req.open("POST", url, async);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
while (reqData.indexOf('/') != -1)
{
reqData = reqData.replace('/', '%2F');
}
reqData = reqData.replace(/\</g, "%3D");
reqData = reqData.replace(/\>/g, "%3E");
//发送请求数据给云端ASPX程序
req.send(reqData);
if (!async)
reqData = reqData.replace(/\</g, "%3D");
reqData = reqData.replace(/\>/g, "%3E");
//发送请求数据给云端ASPX程序
req.send(reqData);
if (!async)
{
if (req.status == 200)
if (req.status == 200)
{
return req.responseText;
}
return req.responseText;
}
else
{
alert('cloud server error');
}
}
alert('cloud server error');
}
}
不多写了,童鞋们知道怎么回事了吧?
现在技术日新月异,终端程序层次不齐,有XAML,HTML5等等,UI虽然越来越绚丽美观了,应用终端也越来越多了,如Android, WP7等,但不变的是后端的服务。精通C#或Java的童鞋赶紧加入云计算的后台来吧!!!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库