This article will introduce to you how to realize the linkage display of data in drop-down boxes based on ajax. The code is very simple. Friends who need it can refer to it
When the company is doing projects, it needs to use the function of linkage display of data in drop-down boxes. , simply use Ajax to implement it. Seeing that I had plenty of time, I didn’t go to the demo to think of a way to write it myself. It's just my own thoughts, some may be mentally retarded, I hope you won't make me laugh.
Two drop-down list boxes in the page:
所在学院: 所在专业:
##JS script code:
public class Handler : IHttpHandler { public void ProcessRequest(HttpContext context) { string type = context.Request.QueryString["type"]; if (type.Equals("college")) { string id = context.Request.QueryString["id"]; context.Response.ContentType = "text/plain"; context.Response.Write(getSpecialty(id));//这个是从数据库中根据传来省的id 查询出来的。学院的名字和主键,主键以便去查专业的名字 } } public string getSpecialty(string college) { DataSet ds = GetInformation.GetSpecialtyInfo(college); string str = ""; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (i == ds.Tables[0].Rows.Count - 1) { str += ds.Tables[0].Rows[i]["SpecialtyID"].ToString() + "," + ds.Tables[0].Rows[i]["SpecialtyName"].ToString(); } else { str += ds.Tables[0].Rows[i]["SpecialtyID"].ToString() + "," + ds.Tables[0].Rows[i]["SpecialtyName"].ToString() + "|"; } } return str.Trim(); } public bool IsReusable { get { return false; } } }

Detailed explanation of ajax synchronization and asynchronousness in jquery
Ajax asynchronous upload in jquery
##
The above is the detailed content of Implementing linkage display of data in drop-down boxes based on Ajax. For more information, please follow other related articles on the PHP Chinese website!