先看一下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的童鞋赶紧加入云计算的后台来吧!!!