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
相关文档:
在上面的示例中,我们定义了两个语法甘露,一个是Class()函数,一个是New()函数。使用Class()甘露,我们已经可以用非常优雅的格式定义一个类。例如前例中的:
var
Employee
=
Class(Person,
//
派生至Person类
{
......
function getOs(){
var OsObject = "";
if(navigator.userAgent.indexOf("MSIE")>0) {
return "MSIE";
}
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
&n ......
代码使用方法:
在介绍正则表达式语法之前先学习下面几个方法:
正则表达式方法:test(),exec()
String对象方法:match(),search(),replace(),split()
test()方法:
用法:regexp对象实例.test(字符串)
返回值:如果满足regexp对象实例中定的正则规则,返回true,否则返回false
exec()方法:
......
用jquery-1.2.3做过几个应用,觉得很好用. 这么快,1.4版又发布了,来自csdn的报道:
CSDN报道 来自jquery官方网站的消息,目前最流行的JavaScript/Ajax库jQuery新版本1.4已经发布,为jQuery项目4周年14天庆祝送上一份大礼。
1.4的压缩版只有23K,未压缩版154K。此外,Google也在自己的服务器上提供了副本,作为Google Ajax A ......