$.ajax json数据传递方法

前台
复制代码 代码如下:




无标题页





点击

接收后台数据

hello




后台
复制代码 代码如下:

protected void Page_Load(object sender, EventArgs e)
{
Hashtable ht = new Hashtable();
string name = Request.Params["name"].ToString();
string birth = Request.Params["birthday"].ToString();
if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(birth))
{
//Response.ContentType = "Application/json";
//Response.Write(CreareJson("this is ok!", 1, name, birth));
ht.Add("info", "成功了");
ht.Add("sta", "状态");
ht.Add("name", name);
ht.Add("birth", birth);
Response.Write(CreateJsonParams(ht));
}
Response.End();
}
private string CreateJsonParams(Hashtable items)
{
string returnStr = "";
foreach(DictionaryEntry item in items)
{
returnStr += "\"" + item.Key.ToString() + "\":\"" + item.Value.ToString() + "\",";
}
return "{" + returnStr.Substring(0,returnStr.Length-1) + "}";
}

你可能感兴趣的:($.ajax json数据传递方法)