传递参数的标准方法(jQuery.ajax)_jquery
程序员文章站
2022-05-24 20:09:38
...
前台
无标题页
后台
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) + "}";
}
}
复制代码 代码如下:
点击
接收后台数据
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) + "}";
}
}