先看一下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>
再看一下HTML介面:
以上是一個非常簡單的Demo,來示範通過HTML介面構造三個輸入框,並調用後代C#邏輯Zivsoft.Business.DemoShow.AddSample實現三個數相加求和的功能。
下面看一下後台C#商務邏輯:
namespace Zivsoft.Business.DemoShow
{
public class AddSample:BaseControl {
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) { reqData = reqData.replace('/', '%2F'); }
reqData = reqData.replace(/\</g, "%3D");
reqData = reqData.replace(/\>/g, "%3E");
//發送請求資料給雲端ASPX程式
req.send(reqData);
if (!async) {
if (req.status == 200) {
return req.responseText;
} else {
alert('cloud server error');
}
}
不多寫了,童鞋們知道怎麼回事了吧?
現在技術日新月異,終端程式層次不齊,有XAML,HTML5等等,UI雖然越來越絢麗美觀了,應用終端也越來越多了,如Android, WP7等,但不變的是後端的服務。精通C#或Java的童鞋趕緊加入雲端運算的後台來吧!!!