• 全部
  • .NET Framework
  • ASP
  • Web Services
  • .NET互联网桌面应用
  • VB
  • 图表区
  • 分析与设计
  • 组件/控件开发
  • AppLauncher
  • 问答

ajax,在客户端可以接受dataset吗?然后对dataset操作吗?

WJY2003 2005-11-29 05:27:40
如:
客户端:
function aa()
{
AjaxMothed.GetDataset(1,bb);
}
function bb(res)
{
res.value.Tables[0].Rows.length;
这个可以有值,但不知这是什么玩意
但是取字段值时就有问题啦
如:alert(res.value.Tables[0].Rows[i]["pageclasssongid"]);
undeifined
}
...全文
273 点赞 收藏 30
写回复
30 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
shamao 2006-05-25
标记
回复
机器人 2005-11-30
dt.Rows[i].chatContent <== 这个chatContent就是列名了。
回复
WJY2003 2005-11-29
有人在吗?
回复
WJY2003 2005-11-29
而在cs程序里我跟踪时,值是的确存在的.
回复
WJY2003 2005-11-29
为什么我这样写:dt.Rows[i].chatContent弹出来的值为undefind,用dt.Rows[i]["chatContent"]也弹出来这个值呢?.这几个字段名是借用你的,嘿嘿,当然在我程序里是替换了的
回复
机器人 2005-11-29
codebehind的代码:
[Ajax.AjaxMethod(HttpSessionStateRequirement.Read)]
public DataSet GetChatContent()
{
User user = null;
OleDbConnection objConn = null;
OleDbCommand objComm = null;
string strConn = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
OleDbDataAdapter objDataAdapter = null;
DataSet ds = new DataSet();
try
{
if(this.Session["User"] != null)
{
user = (User)this.Session["User"];
string strSql = " select * from ChatContent";
strSql += " where (chatTarget='All' ";
strSql += " or chatTarget=@userId) ";
strSql += " and chatDateTime>=@lastDateTime ";
strSql += " and chatDateTime<=@currDateTime ";
strSql += " and beginDate=@beginDate ";
strSql += " order by chatDateTime";

objConn = new OleDbConnection(strConn);
objComm = new OleDbCommand(strSql, objConn);
// userId
objComm.Parameters.Add("@userId", OleDbType.VarChar);
objComm.Parameters["@userId"].Value = user.UserId;
// lastDateTime
objComm.Parameters.Add("@lastDateTime", OleDbType.VarChar, 14);
objComm.Parameters["@lastDateTime"].Value = user.LastQueryDateTime;
// currDateTime
string currDateTime = DateTime.Now.ToString("yyyyMMddHHmmss");
objComm.Parameters.Add("@currDateTime", OleDbType.VarChar, 14);
objComm.Parameters["@currDateTime"].Value = currDateTime;
// beginDate
objComm.Parameters.Add("@beginDate", OleDbType.VarChar, 8);
objComm.Parameters["@beginDate"].Value = user.BeginDate;

user.LastQueryDateTime = currDateTime;

objDataAdapter = new OleDbDataAdapter(objComm);
objConn.Open();
objDataAdapter.Fill(ds);
}
}
finally
{
if(objConn != null)
objConn.Close();
}
return ds;
}
回复
机器人 2005-11-29
当然可以操作DataSet,没有问题。
function RefreshChatContent_CallBack(res)
{
if(res.error != null) {
alert(res.error);
}
else {
var tableChatList = document.getElementById("ChatList");
if(tableChatList == null) return;
var dt = res.value.Tables[0];
for(var i=0; i<dt.Rows.length; i++)
{
if(preChatId != dt.Rows[i].ID)
{
var rowTitle = tableChatList.insertRow();
rowTitle.setAttribute("style", "BORDER-BOTTOM: #9999cc thin solid;MARGIN: 3px", 0);

var colUserId = rowTitle.insertCell();
colUserId.innerHTML = "<b><span style='font-size:11pt'>"+ dt.Rows[i].userId + "</span>   <span style='font-size:10pt'>says:</span></b>";
colUserId.setAttribute("width", "70%", 0);
if(dt.Rows[i].userId == document.getElementById("userId").value)
colUserId.setAttribute("bgcolor", "#cccccc", 0);
else
colUserId.setAttribute("bgcolor", "#99ccff", 0);

var colTime = rowTitle.insertCell();
colTime.innerHTML = "<span style='font-size:9pt'>" + dateTimeFormat(dt.Rows[i].chatDateTime) + "  </span>";
colTime.setAttribute("width", "30%", 0);
colTime.setAttribute("align", "right", 0);
if(dt.Rows[i].userId == document.getElementById("userId").value)
colTime.setAttribute("bgcolor", "#cccccc", 0);
else
colTime.setAttribute("bgcolor", "#99ccff", 0);

var rowContent = tableChatList.insertRow();
var colContent = rowContent.insertCell();
colContent.setAttribute("colspan", "2", 0);
colUserId.setAttribute("width", "100%", 0);
colContent.innerHTML = "<span style='font-size:10pt'>" + dt.Rows[i].chatContent + "</span>";
preChatId = dt.Rows[i].ID;
}
}
var divChatArea = document.getElementById("divChatArea");
if(divChatArea != null)
{
var divHeight = 500;
var scrollHeight = divChatArea.scrollHeight;
divChatArea.scrollTop = scrollHeight - divHeight;
}

}
}
回复
WJY2003 2005-11-29
有人试出来啦吗
回复
WJY2003 2005-11-29
我看了
一样呀
但我的老出错
为什么呀?
回复
startray 2005-11-29
对具体请看:
http://news.csdn.net/news/newstopic/28/28204.shtml
回复
WJY2003 2005-11-29
Ajax还可以返回自定义类,唯一的要求是必须用Serializable属性标记。假设有如下的类:

[Serializable()]
public class User{
private int _userId;
private string _firstName;
private string _lastName;

public int userId{
get { return _userId; }
}
public string FirstName{
get { return _firstName; }
}
public string LastName{
get { return _lastName; }
}
public User(int _userId, string _firstName, string _lastName){
this._userId = _userId;
this._firstName = _firstName;
this._lastName = _lastName;
}
public User(){}
[AjaxMethod()]
public static User GetUser(int userId){
//Replace this with a DB hit or something :)
return new User(userId,"Michael", "Schwarz");
}
}

我们可以通过调用RegisterTypeForAjax注册GetUser代理:

private void Page_Load(object sender, EventArgs e){
Utility.RegisterTypeForAjax(typeof(User));
}

这样就可以在客户端异步调用GetUser:

<script language="javascript">
function getUser(userId){
User.GetUser(GetUser_callback);
}
function GetUser_callback(response){
if (response != null && response.value != null){
var user = response.value;
if (typeof(user) == "object"){
alert(user.FirstName + " " + user.LastName);
}
}
}
getUser(1);
</script>

回复
WJY2003 2005-11-29
好的
我找到了
现发上来大家看看
处理类型

返回复杂类型

Ajax包装器不仅能处理ServerSideAdd函数所返回的整数。它目前还支持integers、strings、double、booleans、DateTime、DataSets和DataTables,以及自定义类和数组等基本类型。其他所有类型都返回它们的ToString值。

返回的DataSets和真正的.NET DataSet差不多。假设一个服务器端函数返回DataSet,我们可以通过下面的代码在客户端显示其中的内容:

<script language="JavaScript">
//Asynchronous call to the mythical "GetDataSet" server-side function
function getDataSet(){
AjaxFunctions.GetDataSet(GetDataSet_callback);
}
function GetDataSet_callback(response){
var ds = response.value;
if(ds != null && typeof(ds) == "object" && ds.Tables != null){
var s = new Array();
s[s.length] = "<table border=1>";
for(var i=0; i<ds.Tables[0].Rows.length; i++){
s[s.length] = "<tr>";
s[s.length] = "<td>" + ds.Tables[0].Rows[i].FirstName + "</td>";
s[s.length] = "<td>" + ds.Tables[0].Rows[i].Birthday + "</td>";
s[s.length] = "</tr>";
}
s[s.length] = "</table>";
tableDisplay.innerHTML = s.join("");
}
else {
alert("Error. [3001] " + response.request.responseText);
}
}
</script>

回复
WJY2003 2005-11-29
你这是返回当时的时间吧/也是一个字符串吧
而不是一个结果集呀?
回复
liushui1981 2005-11-29
http://www.schwarz-interactive.de/
回复
liushui1981 2005-11-29
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
</httpHandlers>

[...]

</system.web>
</configuration>
[AjaxPro.AjaxMethod]
public DateTime GetServerTime()
{
return DateTime.Now;
}

function getServerTime()
{
MyDemo._Default.GetServerTime(getServerTime_callback); // asynchronous call
}

// This method will be called after the method has been executed
// and the result has been sent to the client.

function getServerTime_callback(res)
{
alert(res.value);
}
回复
WJY2003 2005-11-29
TO liushui1981()
ajaxpro.dll在哪儿有?与ajax有什么不同呀?
回复
wwqna 2005-11-29
ie又不支持.net,你怎么去用dataset呀

只能是服务器先转成xml,然后用脚本去读出来
回复
liushui1981 2005-11-29
可以的,,但是要借助AjaxPro.dll
去网上看看!!使用方法
回复
qwerttyy 2005-11-29
swordragon(古道热肠) 写的对的。
回复
WJY2003 2005-11-29
谢谢大家的回答
我传个字符串吧/
回复
相关推荐
发帖
.NET技术社区
创建于2007-09-28

5.8w+

社区成员

.NET技术交流专区
申请成为版主
帖子事件
创建了帖子
2005-11-29 05:27
社区公告
暂无公告