SoFunction
Updated on 2025-03-06

Method for implementing data secondary linkage with jquery+json

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($("&lt;option&gt;&lt;/option&gt;").val(datas[j].ccode).html(datas[j].cityname)); 
   } 
    //Get the information of the area    //GetCountryInfo();
   }); 
}

Background code:

if (["ProID"] != null &amp;&amp; ["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 ( &gt; 0) 
  { 
   (); 
    = .UTF8; 
   (()); 
   (); 
  } 
}
#region Convert to json data according to Datatable's data structurepublic string CreateJsonParameters(DataTable dt) 
{ 
  sb = new (); 
 if (dt != null &amp;&amp;  &gt; 0) 
 { 
  ("["); 
  for (int i = 0; i &lt; ; i++) 
  { 
   ("{"); 
   for (int j = 0; j &lt; ; j++) 
   { 
    //If the value is not the last one, add comma-separation    if (j &lt;  - 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.