This article describes the method of jquery+json to realize data secondary linkage. Share it for your reference, as follows:
function GetCityInfo1() { $("#ddlCITY1").empty(); //$("#ddlCOUNTY").empty(); var strId = $("#ddlPROVINCE1").attr("value"); $('#HiddenPro').val(strId); $.get("../ashx/",{ProID:strId,date:new Date().getTime(),proType:"getCity"},function(result) { $("#ddlCITY1").append($("<option></option>").val("0").html("--Please select city--")); var datas=eval(result); for(var j in datas) { $("#ddlCITY1").append($("<option></option>").val(datas[j].ccode).html(datas[j].cityname)); } //Get the information of the area //GetCountryInfo(); }); }
Background code:
if (["ProID"] != null && ["proType"] != null) { string pcode = (("ProID")[0]); string strSQL = "select cityname,ccode from CD_CityInfo where pcode='" + pcode + "' "; //Execute the T-SQL statement and return DataTable DataTable dt = (strSQL).Tables[0]; StringBuilder sb = new StringBuilder(); (CreateJsonParameters(dt)); //Get information based on province number Get information if ( > 0) { (); = .UTF8; (()); (); } } #region Convert to json data according to Datatable's data structurepublic string CreateJsonParameters(DataTable dt) { sb = new (); if (dt != null && > 0) { ("["); for (int i = 0; i < ; i++) { ("{"); for (int j = 0; j < ; j++) { //If the value is not the last one, add comma-separation if (j < - 1) { ("\"" + [j].() + "\":" + "\"" + [i][j].ToString() + "\","); } //If the value is the last character, no comma is added else if (j == - 1) { ("\"" + [j].() + "\":" + "\"" + [i][j].ToString() + "\""); } } //If it is the last value, no commas are added if (i == - 1) { ("}"); } else { ("},"); } } ("]"); return (); } else { return null; } } #endregion
I hope this article will be helpful to everyone's jQuery programming.