query ajax json 通过后台代码(查询数据库)绑定html控件select 下拉框
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
for (var i = 0; i < jsonObj.length; i++) {
optionstring += "<option value=\"" + jsonObj[i].id + "\" >" + jsonObj[i].name + "</option>"; ;
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$.ajax({
url: "test.asmx/GetSupplier", //后台webservice里的方法名称
{
jsonBuilder.Append("{");
for (int j = 0; j < dt.Columns.Count; j++)
{
jsonBuilder.Append("\"");
}
#endregion
ReturnValue = DataTableJson(dt);
return ReturnValue;
}
#region dataTable转换成Json格式
/// <summary>
/// dataTable转换成Json格式
</body>
</html>
后台websevice里的方法:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
///绑定供应商
public string GetSupplier()
type: "post",
dataType: "json",
contentType: "application/json;charset=utf-8",
data: '{}',
traditional: true,
success: function(data) {
for (var i in data) {
var jsonObj = $.parseJSON(data[i]);
jsonBuilder.Append("{\"");
jsonBuilder.Append(dt.TableName.ToString());
jsonBuilder.Append("\":[");
for (int i = 0; i < dt.Rows.Count; i++)
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<select id="ddl1" name="supplier"></select>
</div>
</form>
jsonBuilder.Append("\",");
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("},");
}
// alert(optionstring);
}
$("#ddl1").html(optionstring);
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public string DataTableJson(DataTable dt)
{
StringBuilder jsonBuilder = new StringBuilder();
}
},
error: function(msg) {
alert("出错了!");
}
});
});
{
string ReturnValue = string.Empty;
string sql = "select * from tb_supplier"; //sql语句
DataTable dt = Common.GetDataSet(sql); //数据库帮助类 返回databale类型
<html xmlns="/1999/xhtml">
<head runat="server">
<title>json测试</title>
?<script src="../../js/jquery-1.5.1.min.js" type="text/javascript"></script>
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("]");
jsonBuilder.Append("}");
return jsonBuilder.ToString();
query ajax json 通过后台代码(查询数据库)绑定html控件select 下拉框
前台代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd">
var optionstriபைடு நூலகம்g = "";
for (var item in jsonObj) {
jsonObj = eval(jsonObj.Table)
jsonBuilder.Append(dt.Columns[j].ColumnName);
jsonBuilder.Append("\":\"");
jsonBuilder.Append(dt.Rows[i][j].ToString());
optionstring += "<option value=\"" + jsonObj[i].id + "\" >" + jsonObj[i].name + "</option>"; ;
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$.ajax({
url: "test.asmx/GetSupplier", //后台webservice里的方法名称
{
jsonBuilder.Append("{");
for (int j = 0; j < dt.Columns.Count; j++)
{
jsonBuilder.Append("\"");
}
#endregion
ReturnValue = DataTableJson(dt);
return ReturnValue;
}
#region dataTable转换成Json格式
/// <summary>
/// dataTable转换成Json格式
</body>
</html>
后台websevice里的方法:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
///绑定供应商
public string GetSupplier()
type: "post",
dataType: "json",
contentType: "application/json;charset=utf-8",
data: '{}',
traditional: true,
success: function(data) {
for (var i in data) {
var jsonObj = $.parseJSON(data[i]);
jsonBuilder.Append("{\"");
jsonBuilder.Append(dt.TableName.ToString());
jsonBuilder.Append("\":[");
for (int i = 0; i < dt.Rows.Count; i++)
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<select id="ddl1" name="supplier"></select>
</div>
</form>
jsonBuilder.Append("\",");
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("},");
}
// alert(optionstring);
}
$("#ddl1").html(optionstring);
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public string DataTableJson(DataTable dt)
{
StringBuilder jsonBuilder = new StringBuilder();
}
},
error: function(msg) {
alert("出错了!");
}
});
});
{
string ReturnValue = string.Empty;
string sql = "select * from tb_supplier"; //sql语句
DataTable dt = Common.GetDataSet(sql); //数据库帮助类 返回databale类型
<html xmlns="/1999/xhtml">
<head runat="server">
<title>json测试</title>
?<script src="../../js/jquery-1.5.1.min.js" type="text/javascript"></script>
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("]");
jsonBuilder.Append("}");
return jsonBuilder.ToString();
query ajax json 通过后台代码(查询数据库)绑定html控件select 下拉框
前台代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd">
var optionstriபைடு நூலகம்g = "";
for (var item in jsonObj) {
jsonObj = eval(jsonObj.Table)
jsonBuilder.Append(dt.Columns[j].ColumnName);
jsonBuilder.Append("\":\"");
jsonBuilder.Append(dt.Rows[i][j].ToString());