A.aspx页面前端脚本
jQuery.ajax({
url: "Search.aspx",data: "UserId=" + info,
cache: false,
success: function (html) {
var t = (jQuery("#lblshow"), (jQuery(html))).text();//获取返回页面控件span 的id 为lblshow的内容
if (t == "") {
jQuery("#ddBank").dialog('close');
} else {
//alert(t);
var gsdm = '';
if (jQuery("#sddlCompanyName").val().indexOf('请选择') > -1)
{ }
else {
gsdm = jQuery("#sddlCompanyName").val();
}
SeachBankCode(t, '', '', '', gsdm);
}
}
});
Search.aspx页面
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Search.aspx.cs" Inherits="Sheets_Search" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<asp:Label ID="lblshow" runat="server" Text=""></asp:Label>
</body>
</html>
Search.aspx后台代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.DBUtility;
public partial class Sheets_Search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.lblshow.Text = "";
string sntext = Request.QueryString["UserId"].ToString().Trim();
if (sntext == "" || sntext == null)
{
this.lblshow.Text = "";
}
else
{
if (DbHelperSQL.Query("select * from ot_user where ObjectID='"+sntext+"'").Tables[0].Rows.Count > 0)
{
this.lblshow.Text = DbHelperSQL.Query("select * from ot_user where ObjectID='" + sntext + "'").Tables[0].Rows[0]["EmployeeNumber"].ToString().Trim();
}
else
{
this.lblshow.Text = "";
}
}
}
}
}
本文介绍了一个使用Ajax进行异步查询的示例,该示例从前端调用后端方法来查询用户信息,并根据查询结果更新界面显示。具体实现中涉及到了jQuery的Ajax请求发送、服务器端的数据接收及处理,以及如何将查询结果返回到前端并展示。
956

被折叠的 条评论
为什么被折叠?



