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
}
...全文
320 30 打赏 收藏 转发到动态 举报
写回复
用AI写文章
30 条回复
切换为时间正序
请发表友善的回复…
发表回复
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
  • 打赏
  • 举报
回复
谢谢大家的回答
我传个字符串吧/
加载更多回复(10)

62,073

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧