javascript, json, xml
【转自】http://www.cnblogs.com/chenxizhang/archive/2010/01/13/1646255.html
在网络编程中,我们经常需要用到javascript,这些客户端脚本又经常需要与服务端进行异步的通讯,提交并接收数据。下面这个例子演示了如何设计服务,如何编写脚本
1. 服务端,这是一个ashx文件
需要添加两个引用 System.Runtime.Serialization和System.ServiceModel.Web
using System.Web;
using System.Web.Services;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
using System.IO;
using System.Text;
namespace DynamicTableSample
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Test : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//解析客户端传过来的数据
var c = context.Request["data"];
var ser = new DataContractJsonSerializer(typeof(Customer));
Customer customer =ser.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(c))) as Customer;//反序列化,将字符串转换为对象
//返回结果
ActionResult result = new ActionResult() { ResultCode = 200, Message = "该操作已经成功" };
var ser2 = new DataContractSerializer(typeof(ActionResult));
//直接返回xml格式的内容。返回xml其实是更好的,因为这个服务才更有通用性。
ser2.WriteObject(context.Response.OutputStream, result);
}
public bool IsReusable
{
get
{
return false;
}
}
}
public class Customer {
public string CustomerID { get; set; }
public Employee[] Employees { get; set; }
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
}
}
public class ActionResult
{
public int ResultC
相关文档:
提供一个简单的例子:
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Key ......
代码使用方法:
在介绍正则表达式语法之前先学习下面几个方法:
正则表达式方法:test(),exec()
String对象方法:match(),search(),replace(),split()
test()方法:
用法:regexp对象实例.test(字符串)
返回值:如果满足regexp对象实例中定的正则规则,返回true,否则返回false
exec()方法:
......
常用的JavaScript验证正则表达式
下面都是我收集的一些比较常用的正则表达式,因为平常可能在表单验证的时候,用到的比较多。特发出来,让各位朋友共同使用。呵呵。
匹配中文字符的正则表达式: [u4e00-u9fa5]
评注:匹配中文还真是个头疼的事,有了这个表达式就好办了
匹配双字节字符(包括汉字在内):[^x00-xff]
评注 ......
‘点正常链接方法很多,这里介绍的是自动点JavaScript链接
Function RunJS(scripts)
‘VB 自动点网页中的Javascript链接
Dim Document
On Error GoTo ErrHandle
......