欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

传递参数的标准方法(jQuery.ajax)_jquery

程序员文章站 2022-05-24 20:09:38
...
前台
复制代码 代码如下:




无标题页




点击

接收后台数据

hello




后台
复制代码 代码如下:

public partial class ajax : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Response.Write("hello"+Request["name"]);
Hashtable ht = new Hashtable();
ht.Add("name", Request.Params["name"]);
ht.Add("id", Request.Params["id"]);
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) + "}";
}
}