<script type="text/javascript" src="js/jquery.js"></script> <script>
function fillHtml(id, href) {
$('#' + id).html("loading...");
$.get(href, function(data) { reveal(id, data); })
}
var reveal = function(id, data) {
$('#' + id).html("");
$('#' + id).append(data);
}
</script>ashx :
public void ProcessRequest(HttpContext context)
{
OleDbConnection con = DBHlepr.CreateDB();
string sql = "select top 8 * from Products where Productstype=1 order by PKID Asc";
OleDbDataAdapter dr = new OleDbDataAdapter(sql, con);
DataTable ds = new DataTable();
dr.Fill(ds);
string str = string.Empty;
for (int i = 0; i < ds.Rows.Count; i++)
{
str += ("<li><a href=\"#\"><img src=\"Img/" + ds.Rows[i]["ProductsUrl"] + "\" /></a><a href=\"#\">" + ds.Rows[i]["ProductsName"] + "</a></li>");
}
context.Response.Write(string.Format("document.write('{0}')", sbHtml.ToString().Replace("\r", "").Replace("\n", "").Replace("\t", "")));
context.Response.End();
}
调用页面: <input id="Button1" type="button" value="button" onclick="fillHtml(pro_one_list1,index.ashx)" />
说我onclick="fillHtml(pro_one_list1,index.ashx)" 出错,第一次用js和jquery 不大懂!~
function fillHtml(id, href) {
$('#' + id).html("loading...");
$.get(href, function(data) { reveal(id, data); })
}
var reveal = function(id, data) {
$('#' + id).html("");
$('#' + id).append(data);
}
</script>ashx :
public void ProcessRequest(HttpContext context)
{
OleDbConnection con = DBHlepr.CreateDB();
string sql = "select top 8 * from Products where Productstype=1 order by PKID Asc";
OleDbDataAdapter dr = new OleDbDataAdapter(sql, con);
DataTable ds = new DataTable();
dr.Fill(ds);
string str = string.Empty;
for (int i = 0; i < ds.Rows.Count; i++)
{
str += ("<li><a href=\"#\"><img src=\"Img/" + ds.Rows[i]["ProductsUrl"] + "\" /></a><a href=\"#\">" + ds.Rows[i]["ProductsName"] + "</a></li>");
}
context.Response.Write(string.Format("document.write('{0}')", sbHtml.ToString().Replace("\r", "").Replace("\n", "").Replace("\t", "")));
context.Response.End();
}
调用页面: <input id="Button1" type="button" value="button" onclick="fillHtml(pro_one_list1,index.ashx)" />
说我onclick="fillHtml(pro_one_list1,index.ashx)" 出错,第一次用js和jquery 不大懂!~
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货