通過HTML調(diào)用C# [架構(gòu)]
先看一下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界面構(gòu)造三個輸入框,并調(diào)用后代C#邏輯Zivsoft.Business.DemoShow.AddSample實現(xiàn)三個數(shù)相加求和的功能。
下面看一下后臺C#業(yè)務(wù)邏輯:
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");
//發(fā)送請求數(shù)據(jù)給云端ASPX程序
req.send(reqData);
if (!async)
reqData = reqData.replace(/\</g, "%3D");
reqData = reqData.replace(/\>/g, "%3E");
//發(fā)送請求數(shù)據(jù)給云端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');
}
}
不多寫了,童鞋們知道怎么回事了吧?
現(xiàn)在技術(shù)日新月異,終端程序?qū)哟尾积R,有XAML,HTML5等等,UI雖然越來越絢麗美觀了,應(yīng)用終端也越來越多了,如Android, WP7等,但不變的是后端的服務(wù)。精通C#或Java的童鞋趕緊加入云計算的后臺來吧!!!
浙公網(wǎng)安備 33010602011771號