Node.js 就是运行在服务端的 JavaScript。
node.js 是一个服务器端运行JavaScript脚本的环境,这个环境下保持了客户端JavaScript的api一致,并且强制使用单进程单线程模式下工作的方式也与运行在浏览器宿主下的javascript保持一致,看似没有其他服务器端语言的任何优势,错了,上面提到的单进程单线程模式其实就是它的一大优点.
用纯js实现点击“记住用户名”按钮,刷新之后用户名依旧在页面的效果方法如下:
1.登录成功之后,把登录信息加密后保存在cookie里面。
2.然后建一个js文件,在这个文件里面做用户是否已登录的判断!如果登录了就直接显示该页面,如果没登录,就跳转回登录页面。
3.这个js文件在登录后才能看到的页面都做引用。
纯js调用webservice接口举例:1、HelloWorld.htm (calls Hello World method):
<html>
<head>
<title>Hello World</title>
<script language="JavaScript">
var iCallID
function InitializeService(){
service.useService(http://localhost:1394/MyWebService.asmx?wsdl,
"HelloWorldService")
service.HelloWorldService.callService("HelloWorld")
}
function ShowResult(){
alert(event.result.value)
}
</script>
</head>
<body onload="InitializeService()" id="service"
style="behavior:url(webservice.htc)" onresult="ShowResult()"></body>
</html>
2、GetAge.htm (calls GetAge method, takes 3 parameters):
<html>
<head>
<title>UseSwap</title>
<script language="JavaScript">
function InitializeService(){
service.useService(http://localhost:1394/MyWebService.asmx?wsdl,
"GetAgeService")
}
var StrYear, StrMonth, StrDay
function GetAge(){
StrYear = document.DemoForm.StringYear.value
StrMonth = document.DemoForm.StringMonth.value
StrDay = document.DemoForm.StringDay.value
service.GetAgeService.callService("GetAge", StrYear, StrMonth, StrDay)
}
function ShowResult(){
alert(event.result.value)
}
</script>
</head>
<body onload="InitializeService()" id="service"
style="behavior:url(webservice.htc)" onresult="ShowResult()">
<form name="DemoForm">
Year : <input type="text" name="StringYear"/>
Month : <input type="text" name="StringMonth"/>
Day : <input type="text" name="StringDay"/>
<button onclick="GetAge()">Get Age</button>
</form>
</body>
</html>
3、GetDateTime.htm (returns cached value):
<html>
<head>
<meta http-equiv="refresh" content="2" />
<title>Get Date Time</title>
<script language="JavaScript">
var iCallID
function InitializeService(){
service.useService(http://localhost:1394/MyWebService.asmx?wsdl,
"GetDateTimeService")
service.GetDateTimeService.callService("GetDateTime")
}
function ShowResult(){
alert(event.result.value)
}
</script>
</head>
<body onload="InitializeService()" id="service"
style="behavior:url(webservice.htc)" onresult="ShowResult()">
</body>
</html>