web前端|js教程
jQuery,json格式
web前端-js教程
客户端用一个html页面调用一个ashx文件(一般http处理程序),返回 json格式的自定义对象:
html:
305sh源码,vscode做盒子代码,Ubuntu释放显存,为什么配置tomcat,色情app爬虫,php round 0,夫唯seo入门教程,用html5做手机网站,仿模板堂资源下载整站源码lzw
$(document).ready(function(){
$("#Button2").click(function(){
var url="handler.ashx?&name="+$("#Text1").val()+"&age="+$("#Text2").val();
$.get(url,function(result){
var obj=eval("("+result+")");
alert("姓名:"+obj.Name+"\n"+"年龄:"+obj.Age);
})
})
})
姓名:<input
type="text" />年龄:
<input
type="text" />
handler.ashx文件:
应用软件下载网站源码,ubuntu修复引导方法,爬虫管理和部署,php 爬虫协议,seo廉价吗lzw
using System;
using System.Web;
using System.Runtime.Serialization.Json;
using System.Collections;
using System.Runtime.Serialization;
public class Handler : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string name = context.Request.Params["name"].ToString();
string age = context.Request.Params["age"].ToString();
person p1 = new person(name,age);
DataContractJsonSerializer djson = new DataContractJsonSerializer(p1.GetType());//将对象序列化为 JavaScript 对象表示法 (JSON)
djson.WriteObject(context.Response.OutputStream, p1);
}
public bool IsReusable {
get {
return false;
}
}
[DataContract]//要序列化,一定要加这个属性
public class person
{
[DataMember]//属性“DataMember”只在“property, indexer, field”声明中有效。
public string Name="无名士";
[DataMember]
public string Age="0";
public override string ToString()
{
return "姓名:" + Name + "年龄:" + Age;
}
public person(string name,string age)//自定义类person
{
this.Name = name;
this.Age = age;
}
public person()
{ }
}
}
一元购源码手机支付,ubuntu如何新建用户,爬虫 保存文章格式,php向上,无经验seolzw